Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

# R,G,Bのそれぞれのインデックスをリストで取得する
r_index = []
g_index = []
b_index = []
for i in range(len(S)):
  if S[i]=='R':
    r_index.append(i)
  elif S[i]=='G':
    g_index.append(i)
  else:
    b_index.append(i)

#　全組み合わせ(制約1)
rgb_num = len(r_index) * len(g_index) * len(b_index)

# 組み合わせを全探索して、制約2に当てはまるものをカウントする
ck = 0
for r in r_index:
  for g in g_index:
    for b in b_index:
      lis = [r, g, b]
      lis.sort()
      i, j, k = lis

      if (j*2 -i -k)==0:
        ck += 1

print(rgb_num - ck)

### FIXED CODE ###

from collections import Counter

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

cnt = Counter(S)

ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(N):
  for j in range(i+1, N):
    k = j + j - i
    if k < N :
      if (S[i] == S[j]) or (S[j] == S[k]) or (S[k] == S[i]) :
        continue
      ans -= 1

print(ans)
### BUGGY CODE ###

N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


def get_path(u, v):
    stack = [u]
    prev = [-1] * (N+1)
    visited = [False] * (N+1)
    visited[u] = True
    while stack:
        node = stack.pop()
        for next in G[node]:
            if not visited[next]:
                visited[next] = True
                prev[next] = node
                stack.append(next)
    path = [v]
    node = v
    while node != u:
        p = prev[node]
        path.append(p)
        node = p
    return path[::-1]


def get_size(paths):
    edges = set()
    for path in paths:
        for i in range(len(path)-1):
            u = path[i]
            v = path[i+1]
            if u > v:
                u, v = v, u
            edges.add((u, v))
    return len(edges)


M = int(input())
uv = [tuple(map(int, input().split())) for _ in range(M)]
paths = [get_path(u, v) for u, v in uv]
ans = 2**(N-1)
for bit in range(1, 1 << M):
    cnt = 0
    tmp = []
    for i in range(M):
        if ((bit >> i) & 1) == 1:
            cnt += 1
            tmp.append(paths[i])
    x = get_size(tmp)
    ans += (-1)**cnt * 2**(N-1-get_size(tmp))
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].append((b, i))
    G[b].append((a, i))


def get_path(u, v):
    stack = [u]
    prev = [None] * (N+1)
    visited = [False] * (N+1)
    visited[u] = True
    while stack:
        node = stack.pop()
        for next, i in G[node]:
            if not visited[next]:
                visited[next] = True
                prev[next] = (node, i)
                stack.append(next)
    path = 0
    node = v
    while node != u:
        p, i = prev[node]
        node = p
        path += 1 << i
    return path


def count(bits, N):
    cnt = 0
    for i in range(N):
        if ((bits >> i) & 1) == 1:
            cnt += 1
    return cnt


M = int(input())
uv = [tuple(map(int, input().split())) for _ in range(M)]
paths = [get_path(u, v) for u, v in uv]
ans = 2**(N-1)
for bit in range(1, 1 << M):
    cnt = 0
    tmp = 0
    for i in range(M):
        if ((bit >> i) & 1) == 1:
            cnt += 1
            tmp |= paths[i]
    ans += (-1)**cnt * 2**(N-1-count(tmp, N-1))
print(ans)
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))

ai = []
aj = []
ans = 0

for i in range(n):
    ai.append(i+l[i])

for j in range(n):
    aj.append(j-l[j])

#print(ai)
#print(aj)

for x in range(n):
    ans = ans + aj.count(ai[x])
    
print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))

a=[]
b={}
ans=0

for i in range(n):
    a.append(i+l[i])
    b[i-l[i]] = b.get(i-l[i],0) + 1

for av in a:
    ans = ans + b.get(av,0)

print(ans)
### BUGGY CODE ###

A, B = map(int, input().split())
ans=1
flag = True
first = 2
while flag:
    flag = False
    for i in range(first,min(A,B)):
        if A % i == 0 and B % i ==0:
            ans += 1
            A //= i
            B //= i
            flag = True
            first = i
print(ans)

### FIXED CODE ###

import fractions
import math

def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a


A, B = map(int, input().split())
max_n = fractions.gcd(A,B)

ans = set(trial_division(max_n))
print(len(ans))
### BUGGY CODE ###

def resolve():


    from collections import deque

    n, m = map(int, input().split())
    ddp = deque(maxlen=2)

    li_broken = [0] * m
    for i in range(m):
        li_broken[i] = int(input())

    ddp.appendleft(0)
    ddp.appendleft(1)

    li_i = list(reversed(range(n)))

    for i in li_i:

        if i in li_broken:
            ddp.appendleft(0)

        else:
            ddp.appendleft(sum(ddp) % 1000000007)

    print(ddp[0])
    
resolve()

### FIXED CODE ###

def step(n):
  if n == 0:
      return 1
  steps = [0 for i in range(n + 2)]
  steps[1] = 1
  steps[2] = 2
  for i in range(3, n + 1):
    steps[i] = steps[i - 1] + steps[i - 2]
  return steps[n]

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

a.append(n)

sum = 1

for i in range(m + 1):

  if i == 0:
    sum *= step(a[i] - 1)
    continue
  
  elif i == m:
    sum *= step(a[m] - a[m-1] -1)
    
  elif a[i] - a[i-1] == 1:
    sum = 0
    break

  else:
    sum *= step(a[i] - a[i-1] -2)
    
if m == 0:
  sum = step(n)

print(sum % 1000000007)
### BUGGY CODE ###

H, W, M = map(int, input().split())

L = [ 0 for i in range(M)]
for i in range(M):
  L[i] = tuple( map(int, input().split()) )

H_val = [ 0 for i in range(H+1)]
W_val = [ 0 for i in range(W+1)]
for i in L:
  H_val[ i[0] ] += 1
  W_val[ i[1] ] += 1
  
Hm = 0
Hs = set()
Wm = 0
Ws = set()
for i in range(1, H+1):
  if H_val[i] == Hm:
    Hs.add(i)
  elif H_val[i] > Hm:
    Hs = {i}
    Hm = H_val[i]
for i in range(1, W+1):
  if W_val[i] == Wm:
    Ws.add(i)
  elif W_val[i] > Wm:
    Ws = {i}
    Wm = W_val[i]
  
flg = False
for i in Hs:
  for j in Ws:
    if (i,j) not in L:
      flg = True
      break
  if flg:
    break
if flg:
  print( Hm + Wm )
else:
  print( Hm + Wm - 1)

### FIXED CODE ###

H, W, M = map(int, input().split())

L = [ 0 for i in range(M)]
for i in range(M):
  L[i] = tuple( map(int, input().split()) )

H_val = [ 0 for i in range(H+1)]
W_val = [ 0 for i in range(W+1)]

H_key = {}
for i in L:
  if i[0] in H_key:
    H_key[ i[0] ].add( i[1] )
  else:
    H_key[ i[0] ] = {i[1]}

for i in L:
  H_val[ i[0] ] += 1
  W_val[ i[1] ] += 1
  
Hm = 0
Hs = set()
Wm = 0
Ws = set()
for i in range(1, H+1):
  if H_val[i] == Hm:
    Hs.add(i)
  elif H_val[i] > Hm:
    Hs = {i}
    Hm = H_val[i]
for i in range(1, W+1):
  if W_val[i] == Wm:
    Ws.add(i)
  elif W_val[i] > Wm:
    Ws = {i}
    Wm = W_val[i]
  
flg = False
for i in Hs:
  for j in Ws:
    if j not in H_key[i]:
      flg = True
      break
  if flg:
    break
if flg:
  print( Hm + Wm )
else:
  print( Hm + Wm - 1)
### BUGGY CODE ###

from operator import itemgetter

h, n = map(int, input().split())
ABs = [list(map(int, input().split())) for i  in range(n)] 

#  dp[i][h] 最初の i 種類の魔法でモンスターに h のダメージを与える場合の、消費魔力の最小値
dp = [[10**9]*(h+1)]*(n+1)
dp[0][0] = 0

for i in range(n):
    for j in range(h):
        a = ABs[i][0]
        b = ABs[i][1]
        # i種類目の魔法を使わない場合
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

        # i種類目の魔法を使う場合
        #min(j+A[i], H) -> hより大きいダメージを与える場合は、与えるダメージをhとして計算する。
        # dp[i+1][j] + b -> i+1種類目の魔法を使った場合の消費魔力
        dp[i+1][min([j+a,h])] = min([ dp[i+1][j] + b, dp[i+1][min([j+a,h])] ])

print(min([row[j+1] for row in dp]))

### FIXED CODE ###

from operator import itemgetter

h, n = map(int, input().split())
ABs = [list(map(int, input().split())) for i  in range(n)] 

#  dp[i][h] 最初の i 種類の魔法でモンスターに h のダメージを与える場合の、消費魔力の最小値
dp = [[10**9]*(h+1)]*(n+1)
dp[0][0] = 0

for i in range(n):
    for j in range(h):
        a = ABs[i][0]
        b = ABs[i][1]
        # i種類目の魔法を使わない場合
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

        # i種類目の魔法を使う場合
        #min(j+A[i], H) -> hより大きいダメージを与える場合は、与えるダメージをhとして計算する。
        # dp[i+1][j] + b -> i+1種類目の魔法を使った場合の消費魔力
        dp[i+1][min([j+a,h])] = min([ dp[i+1][j] + b, dp[i+1][min([j+a,h])] ])

print(min([row[j+1] for row in dp]))
### BUGGY CODE ###

import math
import heapq

N,M = map(int,input().split())
Price_List = list(map(lambda x:x*(-1),map(int,input().split())))
heapq.heapify(Price_List)
for i in range(M):
    heapq.heapify(Price_List)
    val = heapq.heappop(Price_List)/2
    heapq.heappush(Price_List,val)
print(sum(map(lambda x:math.floor(x*(-1)),Price_List)))

### FIXED CODE ###

import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())

ss = [sorted(list(input())) for _ in range(n)]
'''
ss = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    ss.append(tmp)
'''

checked = set()
count = 0

for i in range(n-1):
    if i in checked:
        continue
    same_str = set()
    for j in range(i+1, n):
        if ss[i] == ss[j]:
            count += 1

            for s in same_str:
                count += 1

            same_str.add(j)
            checked.add(j)

print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())

#ss = [sorted(list(input())) for _ in range(n)]
ss = []
checked = {}
count = 0
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = str(tmp)
    if not(tmp in checked):
        checked[tmp] = 1
    else:
        count += checked[tmp]
        checked[tmp] += 1

print(count)
### BUGGY CODE ###

#C - Sum of gcd of Tuples (Easy)
K = int(input())
sum = 0
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum += gcd_list([i,j,k])

print(sum)

### FIXED CODE ###

#C - Sum of gcd of Tuples (Easy)
K = int(input())
DP =[]
ans = 0
import math
# from functools import reduce
# def gcd(*numbers):
#     return reduce(math.gcd, numbers)


# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = math.gcd(i,j)
        for k in range(1,K+1):
            b = math.gcd(a,k)
            ans += b

print(ans)
### BUGGY CODE ###

n = int(input())
V = list(map(int,input().split()))

v1 = []
v2 = []
for i in range(0,n,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
v1s = set(v1)
v2s = set(v2)

v1c = []
v2c = []
v1cc = []
v2cc = []
for i in list(v1s):
  v1c.append([i,v1.count(i)])
  v1cc.append(v1.count(i))
for i in list(v2s):
  v2c.append([i,v2.count(i)])
  v2cc.append(v2.count(i))
  
v1c.sort(key = lambda x:x[1],reverse=True)
v2c.sort(key = lambda x:x[1],reverse=True)
v1cc.sort(reverse=True)
v2cc.sort(reverse=True)

if v1c[0][0] == v2c[0][0]:
  print(min(sum(v1cc[1:])+sum([v2cc[0],sum(v2cc[2:])]),
            sum([v1cc[0],sum(v1cc[2:])])+sum(v2cc[1:])))
else:
  print(sum(v1cc[1:])+sum(v2cc[1:]))

### FIXED CODE ###

n = int(input())
V = list(map(int,input().split()))

from collections import Counter

v1 = []
v2 = []
for i in range(0,n-1,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1).most_common() + [(0,0)]
c2 = Counter(v2).most_common() + [(0,0)]

if c1[0][0] == c2[0][0]:
  a1 = n -c1[1][1]-c2[0][1]
  a2 = n -c1[0][1]-c2[1][1]
  ans = min(a1,a2)
  
else:
  ans = n-c1[0][1]-c2[0][1]

print(ans)
### BUGGY CODE ###

h,w = map(int,input().split())
lis = [list(map(str,input().split("#"))) for i in range(h)]
li = []
for i in range(h):
  s = [0 for i in range(w)]
  cou = 0
  for j in lis[i]:
    e = len(j)
    for n in range(len(j)):
      s[cou] = e
      cou += 1
    cou += 1
  li.append(s)
l = []
for i in range(w):
  s = []
  cou = 0
  for j in range(h):
    if li[j][i] != 0:
      cou += 1
    else:
      cou = 0
    s.append(cou)
  for g in range(h-1):
    if s[-(2+g)] != 0 and s[-(2+g)] < s[-(1+g)]:
      s[-(2+g)] = s[-(1+g)]
  l.append(s)
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,li[i][j] + l[j][i]-1)
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
tate = [[0]*w for i in range(h)]
yoko = [[0]*w for i in range(h)]
s = [str(input()) for i in range(h)]

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,j+1):
                yoko[i][k] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        yoko[i][k] = cnt
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,j):
                tate[k][i] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        tate[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j]-1)
print(ans)
### BUGGY CODE ###

def calc_minus(n):
    return n - 1

n, k, q = map(int, input().split())
a_list = [k] * n
# for _ in range(n):
#     a_list.append(k)
#print(a_list)
for _ in range(q):
    a = int(input())
    a_list = list(map(calc_minus, a_list))
    #print(a_list)
    a_list[a-1] = a_list[a-1] + 1
    #print(a_list)

#print(a_list)
for j in a_list:
    if int(j) > 0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

N,K,Q = map(int, input().split()) #N人、K点、Q問
A = [int(input()) - 1 for i in range(Q)] #受験番号とリスト番号のズレを補正
# print(A)
P = [0] * N #持ち点
for j in range(Q):
    P[A[j]] +=1
for k in range(N):
    if P[k] > Q - K:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from itertools import product
from math import sqrt

def main():
    n = int(input())
    n_copy = n

    if n == 1:
        print(1)
        exit()

    if n % 2 == 0:
        ans = 2 * n - 1
        n *= 2
    else:
        ans = n - 1

    prime = [2, 3]
    for i in range(5, int(sqrt(n_copy)) + 1, 2):
        for p in prime:
            if p * p > i:
                prime.append(i)
                break

            if i % p == 0:
                break

    factors = []
    for p in prime:
        if p * p > n:
            if n > 1:
                factors.append(n)
            break

        if n % p == 0:
            cnt = 0
            while n % p == 0:
                cnt += 1
                n //= p
            factors.append(p ** cnt)

    for tf in product([True, False], repeat=len(factors)):
        a, b = 1, 1
        for i in range(len(factors)):
            if tf[i]:
                a *= factors[i]
            else:
                b *= factors[i]

        if a == 1 or b == 1:
            continue

        if a < b:
            a, b = b, a

        # Euclidean Algorithm
        # a*x - b*y = 1
        # quotient: 商
        l = []
        quo = []
        while a % b > 1:
            l.append(a)
            a = b
            quo.append(0)
            quo[-1], b = divmod(l[-1], b)
        x, y = 1, a//b
        flag = True
        while l:
            if flag:
                x += y * quo.pop()
                b = l.pop()
            else:
                y += x * quo.pop()
                a = l.pop()
            flag = not flag

        if ans > b * y:
            ans = b * y

    print(ans)

main()

### FIXED CODE ###

from itertools import product

def main():
    n = int(input())
    n_copy = n

    if n == 1:
        print(1)
        exit()

    if n % 2 == 0:
        ans = 2 * n - 1
        n *= 2
    else:
        ans = n - 1

    factors = []
    for p in range(2, n):
        if p * p > n:
            if n > 1:
                factors.append(n)
            break

        if n % p == 0:
            cnt = 0
            while n % p == 0:
                cnt += 1
                n //= p
            factors.append(p ** cnt)

    for tf in product([True, False], repeat=len(factors)):
        a, b = 1, 1
        for i in range(len(factors)):
            if tf[i]:
                a *= factors[i]
            else:
                b *= factors[i]

        if a == 1 or b == 1:
            continue

        if a < b:
            a, b = b, a

        # Euclidean Algorithm
        # a*x - b*y = 1
        # quotient: 商
        l = []
        quo = []
        while a % b > 1:
            l.append(a)
            a = b
            quo.append(0)
            quo[-1], b = divmod(l[-1], b)
        x, y = 1, a//b
        flag = True
        while l:
            if flag:
                x += y * quo.pop()
                b = l.pop()
            else:
                y += x * quo.pop()
                a = l.pop()
            flag = not flag

        if ans > b * y:
            ans = b * y

    print(ans)

main()
### BUGGY CODE ###

MAX_A = 10**6 + 1
MAX_P = MAX_A // 2
is_prim = [i%2==1 for i in range(MAX_P)]
is_prim[1] = False; is_prim[2] = True
for i in range(3, MAX_P):
    if not is_prim[i]: continue
    for j in range(i+i, MAX_P, i): is_prim[j] = False

def solve():
    c = 0
    C = [0] * MAX_A
    for a in A:
        for p in [i for i in range(MAX_P) if is_prim[i] and a%i==0]:
            C[p] += 1
            c = max(c, C[p])
    if c <= 1: return "pairwise"
    elif c <= n-1: return "setwise"
    return "not"

n = int(input())
A = [*map(int, input().split())]
print(solve(), 'coprime')


### FIXED CODE ###

n = int(input())
A = [*map(int, input().split())]
def solve():
    MAX_A = 10**6 + 1
    C = [0] * MAX_A
    for a in A: C[a] += 1
    pairwise = True
    for i in range(2, MAX_A):
        if sum(C[i:MAX_A:i]) > 1: pairwise = False
    if pairwise: return 'pairwise'
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    if g == 1: return 'setwise'
    return 'not'
print(solve(), 'coprime')
### BUGGY CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in range(min(a) - 1, max(a) + 2):
    total = 0
    for j in ac:
        if j == i or j + 1 == i or j - 1 == i:
            total += ac[j]
    ans = max(ans, total)
print(ans)

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in range(min(a) - 1, max(a) + 2):
    ans = max(ans, ac[i - 1] + ac[i] + ac[i + 1])
print(ans)
### BUGGY CODE ###

R, G, B, n=map(int, input().split())

r=n//R
g=n//G
b=n//B

cnt=0
for i in range(r+1):
    for j in range(g+1):
        tmp = i*R + j*G
        if (n-tmp)%B == 0 and 0 <= (n-tmp)//B <= b:
            cnt+=1


print(cnt)

### FIXED CODE ###

R, G, B, n=map(int, input().split())

r=n//R
g=n//G
b=n//B

cnt=0
for i in range(r+1):
    for j in range(g+1):
        tmp = i*R + j*G
        if (n-tmp)%B == 0 and 0 <= (n-tmp)//B <= b:
            cnt+=1


print(cnt)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
p=list(set(b))
c=0
for i in range(len(p)):
    if b.count(p[i])>a.count(p[i]):
        c=1
print("YES"if c!=1else"NO")

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a=Counter(a)
m=int(input())
b=list(map(int,input().split()))
b=Counter(b)
for d,e in b.items():
    if a[d]<e:
        print("NO")
        exit()
print("YES")
### BUGGY CODE ###

import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]
x = [int(input()) for _ in range(q)]

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))


### FIXED CODE ###

import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(input())
    s_append(si)
s_append(INF)
t = [-INF]
t_append = t.append
for i in range(b):
    ti = int(input())
    t_append(ti)
t_append(INF)
x = []
x_append = x.append
for i in range(q):
    xi = int(input())
    x_append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))
### BUGGY CODE ###

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	s = input()
	ans = 0
	for l in range(N):
		S = s[l:]
		#print(S)
		A = [0] * (N - l)
		A[0] = N - l

		i = 1
		j = 0
		while i < N - l:
			while i + j < N - l and S[j] == S[i + j]:
				j += 1
			if j == 0:
				i += 1
				continue
			A[i] = j
			k = 1
			while i + k < N - l and k + A[k] < j:
				A[i + k] = A[k]
				k += 1
			i += k
			j -= k
		#print(A)

		for x in range(N - l):
			if A[x] <= x:
				ans = max(ans, A[x])
	print(ans)

if __name__ == '__main__':
	main()

### FIXED CODE ###

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

p = 10 ** 9 + 7
p2 = 10 ** 9 + 9
q = 1007
q2 = 2009

def rollingHash(N, M, A, ans):
	mul1 = 1
	mul2 = 1
	for i in range(M):
		mul1 = (mul1 * q) % p
		mul2 = (mul2 * q2) % p2

	Droll1 = defaultdict(lambda:-1)
	Droll2 = defaultdict(lambda:-1)
	val1 = 0
	val2 = 0
	for i in range(M):
		val1 = val1 * q + A[i]
		val1 %= p
		val2 = val2 * q2 + A[i]
		val2 %= p2

	Droll1[val1] = 0
	Droll2[val2] = 0
	rolling_Hash1 = [None] * (N - M + 1)
	rolling_Hash1[0] = val1
	rolling_Hash2 = [None] * (N - M + 1)
	rolling_Hash2[0] = val2

	for i in range(N - M):
		val1 = (val1 * q - A[i] * mul1 + A[i + M]) % p
		val2 = (val2 * q2 - A[i] * mul2 + A[i + M]) % p2
		rolling_Hash1[i + 1] = val1
		rolling_Hash2[i + 1] = val2

		if Droll1[val1] == -1:
			Droll1[val1] = i + 1
		else:
			if rolling_Hash1[i + 1] == rolling_Hash1[Droll1[val1]] and rolling_Hash2[i + 1] == rolling_Hash2[Droll1[val1]] and i + 1 - Droll1[val1] >= M:
				return M

	return ans

#処理内容
def main():
	N = int(input())
	S = list(input())
	for i in range(N):
		S[i] = ord(S[i]) - 97

	ans = 0
	for i in range(1, int(N // 2) + 1):
		ans = rollingHash(N, i, S, ans)

	print(ans)



if __name__ == '__main__':
	main()
### BUGGY CODE ###

#TLE
S = input()
flag0 = False
flag1 = False
counter = 0
while True:
    idx = S.find("01")
    if idx>=0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag0 = True
    
    idx = S.find("10")
    if idx>=0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag1 = True

    if flag0 and flag1 :
        break
print(counter)

### FIXED CODE ###

from collections import deque
import copy
S = deque(input())
S2 = deque([])
counter = 0
while True:
    flag = True
    while True:
        if len(S) == 0:
            break
        s = S.popleft()
        if len(S2) == 0:
            S2.append(s)
            flag = False
            continue
        
        elif s!=S2[-1]:
            S2.pop()
            flag = False
            counter +=2
        else:
            S2.append(s)
    
    if flag:
        break
    else:
        S = copy.deepcopy(S2)
print(counter)
### BUGGY CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 9
cost = [INF] * N
cost[0] = 0
for i in range(0, N):
    for j in range(1, min(K + 1, N - i)):
        cost[i + j] = min(cost[i + j], cost[i] + abs(H[i] - H[i + j]))

# print (cost)
print (cost[N - 1])

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split())) + [0] * K

INF = 10 ** 9
cost = [INF] * (N + 5 + K)
cost[0] = 0
for i in range(0, N):
    for j in range(1, K + 1):
        cost[i + j] = min(cost[i + j], cost[i] + abs(H[i] - H[i + j]))

# print (cost)
print (cost[N - 1])