Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

def exists(length):
    que = deque()
    V = set()
    T = S[:length]
    que.append(T)
    for s in S[length:]:
        if len(que) >= length:
            V.add(que.popleft())
        T = T[1:] + s
        if T in V:
            return True
        que.append(T)
    return False

for i in range(1, (N + 1) // 2 + 1)[::-1]:
    if exists(i):
        print(i)
        exit()

print(0)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

def exists(length):
    que = deque()
    V = set()
    T = S[:length]
    que.append(T)
    for s in S[length:]:
        if len(que) >= length:
            V.add(que.popleft())
        T = T[1:] + s
        if T in V:
            return True
        que.append(T)
    return False

for i in range(1, N + 1)[::-1]:
    if exists(i):
        print(i)
        exit()

print(0)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

def exists(length):
    que = deque()
    V = set()
    for left in range(N - length + 1):
        if left > length - 1:
            V.add(que.popleft())
        T = S[left: left + length]
        if T in V:
            return True
        que.append(T)
    return False

for i in range(1, N + 1)[::-1]:
    if exists(i):
        print(i)
        exit()

print(0)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

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

strList = defaultdict(deque)

for left in range(N):
    sub = [S[left]]
    strList[''.join(sub)].append(left)
    for right in range(left + 1, N):
        sub.append(S[right])
        strList[''.join(sub)].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

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

strList = defaultdict(deque)

for left in range(N):
    sub = S[left]
    strList[sub].append(left)
    for right in range(left + 1, N):
        sub += S[right]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

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

strList = defaultdict(deque)

for leng in range(N // 2 + 1):
    for left in range(N - leng + 1):
        sub = S[left: left + leng]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

strList = defaultdict(list)

for leng in range(N // 2 + 1):
    for left in range(N - leng + 1):
        sub = S[left: left + leng]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

strList = defaultdict(list)

for leng in range(N):
    for left in range(N - leng + 1):
        sub = S[left: left + leng]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

strList = defaultdict(list)

for leng in range(N):
    for left in range(N - leng + 1):
        sub = S[left: left + leng]
        strList[sub].append(left)

ans = 0
for sub, leftList in strList.items():
    leng = len(sub)
    leftList.sort()
    if leftList[0] + leng <= leftList[-1]:
        ans = max(ans, leng)

print(ans)


Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()

    dp = [[[] for _ in range(N + 1)] for _ in range(N + 1)]  # dp[l1][length] = [l2, l2, ...]

    for l1 in range(N):
        for l2 in range(l1 + 1, N):
            if S[l1] == S[l2]:
                dp[0][l1].append(l2)

    for length in range(1, N):
        for l1 in range(N):
            for l2 in dp[length - 1][l1]:
                if l2 + length >= N:
                    continue
                if l1 + length >= l2:
                    continue
                if S[l1 + length] == S[l2 + length]:
                    dp[length][l1].append(l2)

    ans = 0
    for length in range(N + 1):
        for l1 in range(N + 1):
            if dp[length][l1]:
                ans = max(ans, length + 1)

    print(ans)

sol()

Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()
    T = [-1] * N

    sToIndex = defaultdict(int)
    now = 1

    for i, s in enumerate(S):
        if not s in sToIndex:
            T[i] = now
            sToIndex[s] = now
            now += 1
        else:
            T[i] = sToIndex[s]

    cumT = [0] * (N + 1)
    for i in range(1, N + 1):
        cumT[i] = cumT[i - 1] + T[i - 1]

    cumTList = []
    for left in range(N):
        for right in range(left + 1, N + 1):
            cumTList.append((cumT[right] - cumT[left], left, right))

    matchList = defaultdict(list)
    for v, l, r in cumTList:
        matchList[v].append((l, r))

    ans = 0
    for v, match in matchList.items():
        for i in range(len(match)):
            for j in range(i + 1, len(match)):
                l1, r1 = match[i]
                l2, r2 = match[j]
                if l2 < r1:
                    continue
                if T[l1: r1] == T[l2: r2]:
                    ans = max(ans, r1 - l1)

    print(ans)

sol()

Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()
    T = [-1] * N

    sToIndex = defaultdict(int)
    now = 1

    for i, s in enumerate(S):
        if not s in sToIndex:
            T[i] = now
            sToIndex[s] = now
            now += 1
        else:
            T[i] = sToIndex[s]

    cumT = [0] * (N + 1)
    for i in range(1, N + 1):
        cumT[i] = cumT[i - 1] + T[i - 1]

    cumTList = []
    for left in range(N):
        for right in range(left + 1, N + 1):
            cumTList.append((cumT[right] - cumT[left], left, right))

    matchList = defaultdict(list)
    for v, l, r in cumTList:
        matchList[v].append((l, r))

    ans = 0
    for v, match in matchList.items():
        for i in range(len(match)):
            for j in range(i + 1, len(match)):
                l1, r1 = match[i]
                l2, r2 = match[j]
                if l2 < r1:
                    continue
                if S[l1: r1] == S[l2: r2]:
                    ans = max(ans, r1 - l1)

    print(ans)

sol()

Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    S = input().rstrip()

    ans = 0

    for length in range(1, N // 2 + 2):
        for left in range(N - length + 1):
            sub = S[left: left + length]
            if S[left + length:].find(sub) != -1:
                ans = max(ans, length)

    print(ans)

sol()

Fixed submission:
from collections import deque

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

def isOk(leng):
    hashList = set()
    que = deque([])
    for left in range(N - leng + 1):
        hs = hash(S[left: left + leng])
        if hs in hashList:
            return True
        que.append(hs)
        if len(que) >= leng:
            hashList.add(que.popleft())
    return False

ok = 0
ng = N

while ng - ok > 1:
    mid = (ng + ok) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)