TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
n,s = (input().split())
n = int(n)
if n % 2 == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print('Yes')
    else:
         print('No')

n,s = (input().split())
n = int(n)
if n % 2 == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print("Yes")
    else:
         print("No")

n,s = (input().split())
n = int(n)
if n == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print("Yes")
    else:
         print("No")

n = input()
s = input()
n = int(n)
if n % 2 == 1:
    print("No")
else: 
    t = s[0 : n//2]
    if s[n//2: n] == t:
        print('Yes')
    else:
         print('No')

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
N = int(input())
S = input()
ans = "No"
if N%2 == 0:
  if S[:N//2-1] * 2 == S:
    ans = "Yes"
print(ans)

N = int(input())
S = input()
ans = "No"
if N%2 == 0:
  if S[:N//2] * 2 == S:
    ans = "Yes"
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
n = int(input())
s = input()

if n % 2 != 0:
  print("No")
else:
  half = n // 2
  found = False
  for i in range(0, half + 1):
    if s[i] != s[half + i]:
      found = True
      break
  print("No" if found else "Yes")
  


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

if n % 2 != 0:
  print("No")
else:
  half = n // 2
  found = False
  for i in range(0, half):
    if s[i] != s[half + i]:
      found = True
      break
  print("No" if found else "Yes")
  


Verdicts: Runtime Error

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
n = int(input())
s = list(input())
print(s)
b = n//2
if s[0:b] == s[b:n]:
    print('Yes')
else:
    print('No')

n = int(input())
s = list(input())
b = n//2
if s[0:b] == s[b:n]:
    print('Yes')
else:
    print('No')

Verdicts: Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
N=int(input())
S=input()

if len(S)%2==1:
    print('No')
else:
    for i in range(len(S)//2):
        if S[i]!=S[i+(len(S)//2)]:
            print('No')
            break
        else:
            continue
            print('Yes')

N=int(input())
S=input()

if len(S)%2==1:
    print('No')
else:
    for i in range(len(S)//2):
        if S[i]!=S[i+(len(S)//2)]:
            print('No')
            break
        else:
            continue
        print('Yes')

N=int(input())
S=input()

def onaji(s):
    while True:
        if len(S)%2==1:
            return 'No'
        for i in range(len(S)//2):
            if S[i]!=S[i+(len(S)//2)]:
                return 'No'
            else:
                continue
        return 'Yes'
        
print(onaji(S))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
N = int(input())
S = input()

if N%2 == 1:
  print("NO")
else:
  N_2 = N//2
  if S[:N_2]==S[N_2:]:
    print("YES")
  else:
    print("NO")


N = int(input())
S = str(input())

if N%2 == 0:
  N_2 = int(0.5*N)
  if S[:N_2]==S[N_2:]:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

N = int(input())
S = input()
 
if N%2 == 1:
  print("No")
else:
  N_2 = N//2
  if S[:N_2]==S[N_2:]:
    print("Yes")
  else:
    print("No")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
n=input()
s=input()
if s==n+n:
  print('Yes')
else:
  print('No')

n=int(input())
s=input()
if n%2==1:
    print('No')
else:
    if s[:n//2]==s[n//2:]:
        print('Yes')
    else:
        print('No')

Verdicts: Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
import numpy as np

N = int(input())
S = list(input())

if len(S) % 2 == 1:
  print('NO')
else:
  array = np.array(S).reshape(2, int(N/2))
  array1 = array[0]
  array2 = array[1]
  
  C = np.sum(array1 == array2)
  if C == int(N/2):
    print('YES')
  else:
    print('NO')

import numpy as np

N = int(input())
S = list(input())

if len(S) % 2 == 1:
  print('No')
else:
  array = np.array(S).reshape(2, int(N/2))
  array1 = array[0]
  array2 = array[1]
  
  C = np.sum(array1 == array2)
  if C == int(N/2):
    print('Yes')
  else:
    print('No')

Verdicts: Wrong Answer

Accepted
Problem: Given are a positive integer N and a string S of length N consisting of lowercase English letters.  Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Submission attempts (in order):
N=int(input())
S=input()
if N%2==0:
  if S[:N/2]==S[N/2:]:
    print("Yes")
    exit()
print("No")

N=int(input())
S=input()
if N%2==0:
  if S[:int(N/2)]==S[int(N/2):]:
    print("Yes")
    exit()
print("No")

Verdicts: Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()
dp = [0]*N
j = 1

for i in range(N):
    while S[i:j] in S[j:N]:
        j += 1
    dp[i] = j - i
print(max(dp))


n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))


from collections import defaultdict

def sort_bucket(s, bucket, order):
    d = defaultdict(list)
    for i in bucket:
        key = s[i + order // 2:i + order]
        d[key].append(i)
    result = []
    for k, v in sorted(d.items()):
        if len(v) > 1:
            result += sort_bucket(s, v, 2 * order)
        else:
            result.append(v[0])
    return result

def suffix_array_ManberMyers(s): 
    return sort_bucket(s, (i for i in range(len(s))), 1)
    
def lcp_array(s, sa):
    # http://codeforces.com/blog/entry/12796
    n = len(s)
    k = 0
    lcp = [0] * n
    rank = [0] * n
    for i in range(n):
        rank[sa[i]] = i
        
    for i in range(n):
        if rank[i] == n-1:
            k = 0
            continue
        j = sa[rank[i] + 1]
        while i + k < n and j + k < n and s[i + k] == s[j + k]:
            k += 1
        lcp[rank[i]] = k;
        if k:
            k -= 1
            
    return lcp
  
n = int(input())
s = input()
sa = suffix_array_ManberMyers(s)
e = lcp_array(s, sa)
print(max(e))


n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while S[i:j] in S[j:s]:
        j += 1
    dp[i] = j-i-1
print(max(dp))

n = int(input())
s = input()
dp = [0]*n
j = 1

for i in range(n):
    while s[i:j] in s[j:n]:
        j += 1
    dp[i] = j-i-1
print(max(dp))


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i+1, n+1):
        print('s[i:j]:, s[j:]: ',s[i:j],s[j:], s[i:j] in s[j:], len(s[i:j]))
        if (s[i:j] in s[j:]):
            if ans < len(s[i:j]):
                ans = len(s[i:j])
        else:
            break
print(ans)
            

n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    i = (high+low)//2
    s2 = set()
    for j in range(n-i*2+1):
        s2.add(s[i+j:])
        if s[j:i+j] in s2:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)

import sys
input = sys.stdin.readline
 
def main():
    n = int(input())
    s = input()
    high = n//2
    low = 1
    ans = 0

    while low <= high:
        t = set()
        i = (high+low)//2
        for j in range(n-i*2+1):
            t.add(s[j:i+j])
            if s[i+j:j+2*i] in t:
                if ans < i:
                    ans = i
                    low = i+1
                    break
        if ans < i:
            high = i-1
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
n = int(intput())
s = int(intput())

ans = 0
i = j= 0

while j <= n-1:
    if s[i:j] in s[j:]:
        ans = max(ans, j-i)
        j += 1
    else:
        i += 1
print(ans)

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

ans = 0
i = j= 0

while j <= n-1:
    if s[i:j] in s[j:]:
        ans = max(ans, j-i)
        j += 1
    else:
        i += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
n=int(input())
s=input()
l=0
r=n
while r-l!=1:
  mid=(r+l)//2
  dic={}
  flag=False
  for i in range(n-mid+1):
    tmp=s[i:i+mid]
    if tmp not in dic:
      dic[tmp]=i+mid
    else:
      if dic[tmp]<=i:
        flag=True
        break
  if flag==True:
    l=mid
  else:
    r=mid
print(l,r)

n=int(input())
s=input()
l=0
r=n
while r-l!=1:
  mid=(r+l)//2
  dic={}
  flag=False
  for i in range(n-mid+1):
    tmp=s[i:i+mid]
    if tmp not in dic:
      dic[tmp]=i+mid
    else:
      if dic[tmp]<=i:
        flag=True
        break
  if flag==True:
    l=mid
  else:
    r=mid
print(l)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):

        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1
    
            else:
                ans=max(sign,ans)
                sign=0
                
        ans=max(sign,ans)
        sign=0
        
    ans=max(sign,ans)
    print(s)
    print(ans)
            

if __name__ == '__main__':
    main()

def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):
        if ans>(n-i)//2: break
        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<=j:
                sign+=1
    
            else:
                ans=max(sign,ans)
                sign=0
                
        ans=max(sign,ans)
        sign=0

    ans=max(sign,ans)
    print(ans)
            

if __name__ == '__main__':
    main()

def main():

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

    i,j=0,1
    ans=0
    while j<n:
        if s[i:j] in s[j:]:
            if j-i>ans: ans=j-i
            j+=1
        else:
            i+=1
            j+=1

    print(ans)

            

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()

length = 0 

for i in range(N):
    l1 = i
    l2 = i + length
    _word = S[l1:l2]
    _S = S[l2:]
    while _word in _S and l1 + len(_word) < l2:
        l2 += 1
        _word = S[l1:l2]
        _S = S[l2:]
    length = max(len(_word)-1, length)

print(length)


N = int(input())
S = input()

length = 0 

for i in range(N):
    l1 = i
    l2 = i + length
    _word = S[l1:l2]
    _S = S[l2:]
    while _word in _S:
        l2 += 1
        _word = S[l1:l2]
        _S = S[l2:]
    length = max(len(_word)-1, length)

print(length)


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
n=int(input())
t=input()
s=set()
a=-1
for i in range(n):
  for j in range(i+1,n+1):
    m=t[i:j]
    if m in s:a=max(a,j-i)
    else:s.add(t[i:j])
print(a)

n=int(input())
s=list(map(ord,list(input())))
for i in range(n):s[i]-=97

from random import randint
roli_mod=1370757747362922367
roli_r=randint(2,roli_mod-2)
roli=[0]
roli_rr=1
for i in range(n):
  roli.append((roli[-1]+roli_rr*s[i])%roli_mod)
  roli_rr*=roli_r
  roli_rr%=roli_mod
def roli_hash(i,j):return ((roli[j+1]-roli[i]+roli_mod)%roli_mod)*pow(roli_r,roli_mod-1-i,roli_mod)%roli_mod
def roli_check(i1,j1,i2,j2):return roli_hash(i1,j1)==roli_hash(i2,j2)

ok=0
ng=(n+1)//2+1
while ok+1!=ng:
  i=(ok+ng)//2
  d={}
  f=False
  for j in range(n-i+1):
    h=roli_hash(j,j+i-1)
    if h in d:
      if j-d[h]>=i:
        f=True
        break
    else:d[h]=j
  if f:ok=i
  else:ng=i
print(ok)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
# 2019-11-18 17:34:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    res = 0
    l, r = 0, 1
    while r <= l + (n - l) // 2:
        t = s[l:r]
        if t in s[r:]:
            ans = max(res, r - l)
            r += 1
        else:
            l += 1
            if l == r:
                r += 1
    print(res)

if __name__ == "__main__":
    main()



# 2019-11-18 17:34:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    res = 0
    l, r = 0, 1
    while r <= l + (n - l) // 2:
        t = s[l:r]
        if t in s[r:]:
            res = max(res, r - l)
            r += 1
        else:
            l += 1
            if l == r:
                r += 1
    print(res)

if __name__ == "__main__":
    main()



Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
def z_arr(s):
    """An advanced computation of Z-values of a string."""
    # From https://ivanyu.me/blog/2013/10/15/z-algorithm/

    Z = [0] * len(s)
    Z[0] = len(s)

    rt = 0
    lt = 0

    for k in range(1, len(s)):
        if k > rt:
            # If k is outside the current Z-box, do naive computation.
            n = 0
            while n + k < len(s) and s[n] == s[n+k]:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k+n-1
        else:
            # If k is inside the current Z-box, consider two cases.

            p = k - lt  
            right_part_len = rt - k + 1

            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k]:
                    i += 1
                Z[k] = i - k

                lt = k
                rt = i - 1
    return Z

if __name__=="__main__":
    s=input()
    ans=0
    for i in range(len(s)):
        A=z_arr(s[i:])
        for a in range(len(A)):
            if A[a]<=a:
                ans=max(ans, A[a])

N = int(input())
S = input()
 
r = 0
ans = 0
for l in range(N):
 
    while True:
        #print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
 
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break
 
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
# -*- coding: utf-8 -*-
# E


import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline




n = int(input())
s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod

def check2(m):
    
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod
    dic = defaultdict(int)
    dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


def check3(m):
    dic = {}
    for i in range(n-m+1):
        s = s[i:i+m]
        if s in dic.keys():
            if dic[s]+m<=i:
                return True
        else:
            dic[s] = i
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)




print(lb)

# -*- coding: utf-8 -*-
# E



import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline




n = int(input())
s = input()[:-1]

# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


def check3(m):
    
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod

def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    
    
    

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)




print(lb)

Verdicts: Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
import numpy as np


def solve(n, s, MOD):
    d = 26
    s = np.array([ord(c) - 97 for c in s], dtype=np.int64)
    max_l = n // 2

    vec = [1]
    for i in range(max_l - 1):
        vec.append(vec[-1] * d % MOD)
    vec.reverse()
    vec = np.array(vec, dtype=np.int64)

    for l in range(max_l, 0, -1):
        cnv = np.convolve(s, vec, 'valid') % MOD
        appeared = set()
        for i, w in enumerate(cnv[l:], start=l):
            if w in appeared:
                return l
            appeared.add(cnv[i - l])

        vec = vec[1:]

    return 0


n = int(input())
s = input()
print(solve(n, s, 10 ** 9 + 7))


def solve(n, s):
    l, r = 0, n // 2 + 1
    while l < r:
        m = (l + r + 1) // 2
        if search(m, s):
            l = m
        else:
            r = m - 1
    return l


def search(w, s):
    w2 = w * 2
    appeared = [hash(s[i - w:i]) for i in range(w, w2)]
    comparing = set()

    for i in range(w2, n + 1):
        t = hash(s[i - w:i])
        comparing.add(appeared[i - w2])
        if t in comparing:
            return True
        appeared.append(t)

    return False


n = int(input())
s = input()
print(solve(n, s))


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
import sys

input = sys.stdin.readline

def main():
    def hash_ini(t):
        h = t[0]
        hash_table[0] = h
        p = 1
        for i in range(1, len(t)+1):
            h = hash_table[i] = (h * base + t[i]) % hash_md
            p = pw[i] = p * base % hash_md

    def hash(s):
        res = 0
        for i, c in enumerate(s[::-1]):
            res = (res + pw[i] * (ord(c) - ord_a)) % hash_md
        return res

    
    def hash_ij(i, j):
        return (hash_table[j] - hash_table[i] * pw[j - i]) % hash_md

    n = int(input())
    s = input()[:-1]

    
    base = 29
    hash_md = pow(3, 19)
    ord_a = ord('a')
    t = [ord(c) - ord_a for c in s]
    hash_table = [0] * (len(t)+1)
    pw = [1] * (len(t)+1)
    hash_ini(t)

    ok = 0
    ng = n // 2 + 1
    while ok + 1 < ng:
        br = False
        w = (ok + ng) // 2
        for i in range(n - 2 * w + 1):
            ptn = hash_ij(i, i + w)
            for j in range(i + w, n - w + 1):
                if hash_ij(j, j + w) == ptn:
                    ok = w
                    br = True
                    break
            if br: break
        else:
            ng = w
    print(ok)

main()


import sys

input = sys.stdin.readline

def main():
    def hash_ini(t):
        h = 0
        p = 1
        for i in range(1, len(t) + 1):
            h = hash_table[i] = (h * base + t[i - 1]) % hash_md
            p = pw[i] = p * base % hash_md

    
    def hash_ij(i, j):
        return (hash_table[j] - hash_table[i] * pw[j - i]) % hash_md

    n = int(input())
    s = input()[:-1]

    
    base = 31
    hash_md = pow(3, 19)
    ord_a = ord('a')
    t = [ord(c) - ord_a for c in s]
    hash_table = [0] * (len(t) + 1)
    pw = [1] * (len(t) + 1)
    hash_ini(t)

    
    ok = 0
    ng = n // 2 + 1
    while ok + 1 < ng:
        w = (ok + ng) // 2
        hashes = []
        for i in range(w):
            hashes.append(hash_ij(i, i + w))
        passed = set()
        for i in range(w, n - w + 1):
            passed.add(hashes[i - w])
            cur = hash_ij(i, i + w)
            if cur in passed:
                ok = w
                break
            hashes.append(cur)
        else:
            ng = w

    print(ok)

main()


Verdicts: Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()

def z_algo(S):
    
    N = len(S)
    A = [- 1]*N 
    A[0] = N 
    j = 1 
    i = 1 
    while i < N: 
        c = j + A[j] - i
        if c <= 0:
            k = 0
            while i + k < N and S[k] == S[i + k]:
                k += 1
            A[i] = k
            j = i
        elif c > 0:
            if A[i - j] == c:
                k = 0
                while i + k + c < N and S[c + k] == S[i + c + k]:
                    k += 1
                A[i] = c + k
                j = i
            elif A[i - j] > c:
                A[i] = c
                j = i
            else:
                A[i] = A[i - j]
        i += 1
    return A

res = 0
for i in range(0, N - 1):
    res = max(res, max(z_algo(S[i:])[1:]))
print(res)

N = int(input())
S = input()
k = 1
for i in range(N - 1):
    while True:
        if S[i : i + k] in S[i + k :]:
            k += 1
        else:
            break
print(l)

N = int(input())
S = input()
S += '0'
l = 0
for i in range(N):
    for j in range(i + 1, N):
        f = True
        for k in range(min(j - i, N - j + 1)):
            if S[i : i + k] == S[j : j + k] :
                pass
            else:
                break
        l = max(l,  k)
        
print(l)

N = int(input())
S = input()
def Zalgo(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i = 1
    j = 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        A[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < N and k + A[k] < j:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k
res = 0
for i in range(N - 1):
    lcp = Zalgo(S[i:])
    for j in range(N - i):
        l = min(j, lcp[j])
        res = max(l, res)
print(res)

N = int(input())
S = input()
ans = 0
right = 0
for left in range(N - 1):
    while right < N and (S[left : right] in S[right :]):
        right += 1
    if left == right:
        right += 1
    ans = max(ans, right - left - 1)
print(ans)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S =  input()
n_list = [0] * N
max_length = 0
max_reach = -1
for i in range(N):
    if i < max_reach:
        continue
    for j in range(i+max_length,N):
        if S[i:j] in S[j:N]:
            continue
        else:
            if j == max_length:
                break
            elif j > max_length:
                max_length = j-1
                max_reach = i+j-1
                break
print(max_length)

N = int(input())
S =  input()
n_list = [0] * N
max_length = 0
for i in range(N):
    for j in range(max_length,N):
        if S[i:j] in S[j:N]:
            continue
        else:
            current_length = j-i-1
            if current_length > max_length:
                max_length = current_length
            break
print(max(n_list))

n = int(input())
S = input()
N = [0]*n
j = 0
 
for i in range(n):
  while S[i:j] in S[j:n]:
    N[i] = j-i
    j += 1
    
print(max(N))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()


r = 0
ans = 0
for l in range(N):

    while True:
        print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
        
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break

print(ans)


N = int(input())
S = input()


r = 0
ans = 0
for l in range(N):

    while True:
        # print(S.rfind(S[l:r+1]), S[l:r+1], l, r)
        
        if S.rfind(S[l:r+1]) >= r+1:
            r += 1
            ans = max(ans, r-l)
        else:
            break

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
def main():
    N = int(input())
    S = input()
    ans = 0

    for i in range(N):
        s1 = S[0:i+1]
        s2 = S[i+1:N]
        print(s1, s2)
        if s1 in s2 and len(s1) < len(s2):
            ans = i+1
        else:
            cache_ans = ans
            for j in range(i):
                s = s1[1 + j:]
                if s in s2:
                    ans = len(s)
                    break
            if len(s2) > ans and len(s1) > len(s2):
                break

    print(ans)

if __name__ == '__main__':
    main()


def main():
    N = int(input())
    S = input()
    ans = 0
    index = 0

    for i in range(N):
        s1 = S[index:i+1]
        s2 = S[i+1:]
        if s1 in s2:
            ans = len(s1)
        else:
            index += 1

    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()


def isok(n):
    for i in range(N-2*n+1):
        now = S[i:i+n]
        if S[i+n:].find(now) != -1:
            return True
    return False


left = 0
right = N//2

while right - left > 1:
    mid = left + (right-left)//2
    if not isok(mid):
        right = mid
    else:
        left = mid

print(left)


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

import random
base1 = 1007
mod1 = 10**9+7
modTank1 = [3000012541,3000012553,3000012563,3000012649,3000012683,3000012709]
mod1 = modTank1[random.randint(0,5)]
base1 = 1007
mod1 = 10**9+7
hash1 = [0]*(n+1)
power1 = [1]*(n+1)
for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1
def rolling_hash(i, j):
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1



hash = set()
l = 0
r = n
while r - l > 1:
    m = l + (r-l)//2
    hash = dict()
    flag = 0
    for i in range(n-m+1):
        h = rolling_hash(i, i+m)
        if h not in hash.keys():
            hash[h] = i
        elif hash[h]+m <= i:
            flag = 1
            break
    if flag == 1:
        l = m
    else:
        r = m

print(l)


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N=int(input())
String=input()
max=0

for f in range(len(String)):
    S=String[f:]
    A = [0] * len(S)
    A[0] = len(S)
    i, j = 1, 0
    #print(S)
    while(i<len(S)):
        #print(A)
        #print("i= " + str(i) + "j= " + str(j))
        while(i+j<len(S) and S[j]==S[i+j]):
            #print("i= "+str(i)+"j= "+str(j))
            j+=1
        A[i]=j
        if(j>max):
            max=j
        if(j==0):
            i+=1
            continue
        k=1
        while(k+i<len(S) and k+A[k]<j):
            A[i+k]=A[k]
            k+=1
        i+=k
        j=0


#print(A)
print(max)

N=int(input())
S=input()

max = 0
index = 0
for i in range(1,len(S)-1):
    s1=S[index:i]
    s2=S[i:]
    if s1 in s2:
        max=len(s1)
    else:
        index+=1
        
print(max)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
n=int(input())
s=input()

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

n = int(input())
s = input().rstrip()
 
 
def check(length):
    d = set()
    for i in range(n - 2 * length + 1):
        d.add(s[i:i + length])
        if s[i + length:i + 2 * length] in d:
            return True
    return False
 
 
lo = 0
hi = n // 2 + 1
while lo + 1 < hi:
    mid = (lo + hi) // 2
    if check(mid):
        lo = mid
    else:
        hi = mid
print(lo)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
#!/usr/bin/env python
# coding: utf-8

# In[2]:


N = int(input())
S = input()
"""
13
strangeorange
5
"""


# In[17]:


dp = [[0]*(N+1) for i in range(N+1)]


# In[18]:


max_cont = 0
for i in range(N)[::-1]:
    for j in range(N)[::-1]:
        if i < j:
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1]+1
                max_cont = max(max_cont, dp[i][j])
            else:
                continue
        else:
            continue


# In[19]:


print(max_cont)


# In[ ]:






#!/usr/bin/env python
# coding: utf-8

# In[49]:


#import numpy as np
N = int(input())
S = input()
"""
5
ababa
2

13
strangeorange
5
"""


# In[54]:


i = 0
j = 1
max_cont = 0

while j < N:
    if S[i:j] in S[j:]:
        max_cont = max(max_cont, len(S[i:j]))
        j += 1
    else:
        i += 1
    if i == j:
        i += 1
        j += 2


# In[55]:


print(max_cont)


# In[ ]:






Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
from collections import Counter

def get_substrings(length, string):
    substrings = [''.join(string[i:i+length]) for i in range(len(string)-length+1)]
    return substrings

N = int(input())
S = input()
ans = 0
for i in range(N//2 + 1, 0, -1):
    substrings = Counter(get_substrings(i, S))
    if substrings.most_common(1)[0][1] >= 2:
        ans = i
        break
print(ans)

N = int(input())
S = input()
ans = [0] * N
j = 1
for i in range(N):
    while S[i:j] in S[j:N]:
        ans[i] = j - i; j += 1
print(max(ans))

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()

def check(l):
    D = set()
    for i in range(N - 2 * l + 1):
        D.add(S[i:i+l])
        if S[i+l:i+2*l] in D:
            return True

for i in range(N // 2 + 1):
    if not check(i):
        break

print(i - 1)

N = int(input())
S = input()

def check(l):
    D = []
    for i in range(N - 2 * l + 1):
        D.append(S[i : i + l])
        if S[i + l : i + 2 * l] in D:
            return True

ok = 0
ng = N // 2 + 1

while ng - ok > 1:
    m = (ok + ng) // 2
    if check(m):
        ok = m
    else:
        ng = m

print(ok)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
S = input()

ans = 0
for kosu in range(1, N//2+1):
    hantei = False
    for i in range(N-kosu):
        if hantei:
            break
        else:
            temp = S[i:i+kosu]
            # print("temp:", temp)
            
        if temp in S[0:i]+S[i+1:]:
            
            ans = len(list(temp))
            hantei = True
            breaks
print(ans)


N = int(input())
S = input()
l1 = length = 0
l2 = 1

while (l2 + length < N):
    if S[l1:l2] in S[l2:]:
        length = l2 - l1
        l2 += 1
    else:
        l1 += 1
        l2 = l1 + length + 1
print(length)


Verdicts: Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
# -*- coding: utf-8 -*-                                                         
tmp = input()
my_str = input()

start = 0
end = 1
max_len = 0

while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        end += 1
        if end - start > max_len:
            max_len = end - start
    else:
        start += 1

print(max_len)


# -*- coding: utf-8 -*-                                                         
tmp = input()
my_str = input()

start = 0
end = 1
max_len = 0

while (end + max_len < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        end += 1
        if end - start > max_len:
            max_len = end - start
    else:
        start += 1

print(max_len)


# -*- coding: utf-8 -*-                                                         
tmp = input()
my_str = input()

start = 0
end = 1
max_len = 0

while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        if end - start > max_len:
            max_len = end - start
     	end += 1
    else:
        start += 1

print(max_len)


# -*- coding: utf-8 -*-
tmp = input()
my_str = input()

start = 0
end = 1
max_len = 0

while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        if end - start > max_len:
            max_len = end - start
        end += 1
    else:
        start += 1

print(max_len)


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
import sys
input = sys.stdin.readline
from math import ceil
N = int(input())
S = input()

res = 0
for st in range(len(S)-1):
    s = S[st:]
    lens = len(s)
    A = [0]*lens
    c = 0
    for i in range(1, lens):
        if i+A[i-c] < c+A[c]:
            A[i] = A[i-c]
        else:
            j = max(0, c+A[c]-1)
            while i+j < lens and s[j] == s[i+j]:
                j += 1
            A[i] = j
    A[0] = lens

    res = max(res, max(A[ceil(len(A)/2):]))

print(res)


N = int(input())
S = input()

i = 0
j = 1
res = 0
while j < N:
    sub = S[i:j]
    main = S[j:]
    if sub in main:
        j += 1
        res = max(res, len(sub))
    else:
        i += 1
    if i == j:
        i += 1
        j += 2
print(res)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S of length N.  Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.  More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:    * l_1 + len \leq l_2    * S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)  If there is no such integer len, print 0.

Submission attempts (in order):
N = int(input())
St = input()
ans = 0


dp=[[0 for i in range(N+1)] for j in range(N+1)]


for i in range(N-1):
  for j in range(N-1, i-1, -1):
    dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    if St[i] == St[j]:
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
      
ans = 0
for i in range(N):
  ans = max(ans, dp[i][i+1])
print(ans)

N = int(input())
St = input()
ans = 0


dp=[[0 for i in range(N)] for j in range(N)]


for i in range(N-1):
  for j in range(N-1, i, -1):
    dp[i+1][j-1] = max(dp[i][j-1],dp[i+1][j])
    if St[i] == St[j-1]:
      dp[i+1][j-1] = max(dp[i+1][j-1], dp[i][j]+1)
      
ans = 0
for i in range(N):
  ans = max(ans, dp[i][i])
print(ans)

N = int(input())
S = input()
length = N//2

while length:
  strings = [S[i:i+length] for i in range(N-length+1)]
  print(length, strings)
  for i in range(N-length+1):
    for j in range(i+length,N-length+1):
      if S[i:i+length] == S[j:j+length]:
        print(length)
        break
  
  length -= 1
else:
  print(0)

N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = S[i:i+l]
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted