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

N, B, R = map(int, input().split())

Line = ''

while(N > len(Line)):
  for i in range(B):
    Line += 'b'
  for i in range(R):
    Line += 'r'

ans = Line[:N].count('b')

print(ans)

### FIXED CODE ###

N, B, R = map(int, input().split())

ans = (N // (B+R)) * B
rest = N % (B+R)

if rest <= B:
  print(ans+rest)
else:
  print(ans+B)
### BUGGY CODE ###

from itertools import combinations
from collections import Counter
n=int(input())
s=input()
a=list(s)
c=list(combinations(a,3))

num=len(Counter(c))
print(num)


### FIXED CODE ###

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

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for p in range(len(s)):
                if s[p]==str(i):
                    for q in range(p+1,len(s)):
                        if s[q]==str(j):
                            for r in range(q+1,len(s)):
                                if s[r]==str(k):
                                    ans+=1
                                    break
                            break
                    break

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

import itertools
n = int(input())
s = input()
dat = []
for i in range(n):
    dat.append(set([]))
for i in range(n):
    for j in range(i, 0, -1):
        for x in dat[j-1]:
            dat[j].add(x + s[i])
    dat[0].add(s[i])
print(len(dat[2]))
#print(dat[2])

### FIXED CODE ###

n = int(input())
s = input()
res = 0
pos = []
for i in range(10):
    pos.append([])

for i in range(len(s)):
    c = int(s[i])
    pos[c].append(i)
import bisect
# 0010
# print(format(10, '04d'))
res = 0
for num in range(0, 1000):
    numstr = format(num, '03d')
    iscan = True
    curpos = -2
    for i in range(3):
        curpos += 1
        val = int(numstr[i])
        ind = bisect.bisect_left(pos[val], curpos)
        if ind == len(pos[val]):
            iscan = False
            break
        curpos = pos[val][ind]

    if iscan:
        res += 1
print(res)
### BUGGY CODE ###

h,w=map(int,input().split())
inf=float("inf")
d=((-1,0),(1,0),(0,-1),(0,1))
S=[["#"]*(w+2)]
S.extend([["#"]+[s for s in input()]+["#"] for _ in range(h)])
S.append(["#"]*(w+2))
import collections
def dist(a,b):
  if S[a][b]=="#":
    return 0
  else:
    D=[[inf]*(w+2) for _ in range(h+2)]
    D[a][b]=0
    Visit=collections.deque()
    Visit.append(100*a+b)
    while Visit:
      v=Visit.pop()
      va,vb=v//100,v%100
      for dx,dy in d:
        if S[va+dx][vb+dy]=="#":
          continue
        elif D[va+dx][vb+dy]>D[va][vb]+1:
          Visit.append((va+dx)*100+(vb+dy))
          D[va+dx][vb+dy]=D[va][vb]+1
    ret=0
    for i in range(h):
      for j in range(w):
        if D[i+1][j+1]<inf:
          ret=max(ret,D[i+1][j+1])
    return ret
ans=0
for i in range(h):
  for j in range(w):
    ans=max(dist(i+1,j+1),ans)
print(ans)





### FIXED CODE ###

h,w=map(int,input().split())
inf=float("inf")
d=((-1,0),(1,0),(0,-1),(0,1))
S=[["#"]*(w+2)]
S.extend([["#"]+[s for s in input()]+["#"] for _ in range(h)])
S.append(["#"]*(w+2))

def dist(a,b):
  if S[a][b]=="#":
    return 0
  else:
    D=[[inf]*(w+2) for _ in range(h+2)]
    D[a][b]=0
    Visit=[100*a+b]
    while Visit:
      v=Visit.pop()
      va,vb=v//100,v%100
      for dx,dy in d:
        if S[va+dx][vb+dy]=="#":
          continue
        elif D[va+dx][vb+dy]>D[va][vb]+1:
          Visit.append((va+dx)*100+(vb+dy))
          D[va+dx][vb+dy]=D[va][vb]+1
    ret=0
    for i in range(h):
      for j in range(w):
        if D[i+1][j+1]<inf:
          ret=max(ret,D[i+1][j+1])
    return ret
ans=0
for i in range(h):
  for j in range(w):
    ans=max(dist(i+1,j+1),ans)
print(ans)
### BUGGY CODE ###

import itertools

def main():
    N = int(input())
    S = input()
    lst = list(S)

    sets = set()
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = str(lst[i])+str(lst[j])+str(lst[k])
            if s not in sets:
                sets.add(s)
    print(len(sets))

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = ['{:03d}'.format(i) for i in range(1000)]
    count = 0
    for i in range(len(a)):
        m,n,o = 0,1,2
        s = list(a[i])
        while m < n < o < len(lst) :
            if s[0] != lst[m]:
                m += 1
                n += 1
                o += 1
            elif s[1] != lst[n]:
                n += 1
                o += 1
            elif s[2] != lst[o]:
                o += 1
            else:
                count += 1
                break

    print(count)

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

X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

x = []
for a in A:
    for b in B:
        for c in C:
            x.append(a + b + c)
x.sort(reverse=True)

for i in range(K):
    print(x[i])
    

### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])
ab.sort(reverse = True)

abc = []
for i in range(min(k,len(ab))):
    for j in range(z):
        abc.append(ab[i] + c[j])

abc.sort(reverse = True)

for i in range(k):
    print(abc[i])
### BUGGY CODE ###

# import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input()
a_list = [int(s) for s in input().split()]

N = len(a_list)
min_last_hp = 10**10
for start in range(N):
    for c in range(start+1, N):
        if a_list[start] % a_list[c] == 0:
            last_hp = a_list[c]
        elif a_list[c] % a_list[start] == 0:
            last_hp = a_list[start]
        else:
            continue
        # if min_last_hp == None:
        #     min_last_hp = last_hp
        if last_hp < min_last_hp:
            min_last_hp = last_hp

f = min(a_list)
a_list.remove(f)
s = min(a_list)
kouho=gcd(f,s)
if kouho < min_last_hp:
    print(kouho)
else:
    print(min_last_hp)


### FIXED CODE ###

# import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input()
a_list = [int(s) for s in input().split()]

N = len(a_list)
min_last_hp = 10**10

f = min(a_list)
a_list.remove(f)

for i in a_list:
    last_hp = gcd(f, i)
    if last_hp < min_last_hp:
        min_last_hp = last_hp

s = min(a_list)
kouho=gcd(f,s)
if kouho < min_last_hp:
    print(kouho)
else:
    print(min_last_hp)
### BUGGY CODE ###

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

for i in range(m-1):
    if m == 1:
        break
    if a[i+1] - a[i] == 1:
        print(0)
        exit()

dp = [0] * (n+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i - 2]
    dp[i] %= 1000000007

print(dp[n])


### FIXED CODE ###

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

dp = [0] * (n+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i - 2]
    dp[i] %= 1000000007

print(dp[n])
### BUGGY CODE ###

import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    a = n
    while True:
        b = abs(a-k)
        if b == 0:
            print(0)
            sys.exit()
        elif b == 1:
            print(1)
            sys.exit()
        elif a < b:
            print(a)
            sys.exit()
        a = b
    print(a)
    sys.exit()
    
min_N(n, k)

### FIXED CODE ###

import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))
### BUGGY CODE ###

a,b,c,d = map(int,input().split())
ans = 0
for i in range(a,b+1):
         if i%c != 0 and i%d != 0:
                  ans += 1
print(ans)


### FIXED CODE ###

import fractions
a,b,c,d = map(int,input().split())
lcm = (c*d)//fractions.gcd(c,d)
print(((b-((b//c)+(b//d)-(b//lcm)))-((a-1)-(((a-1)//c)+((a-1)//d)-((a-1)//lcm)))))
### BUGGY CODE ###

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

sort_h_list = sorted(h_list, reverse=True)
sort_h_list_length = len(sort_h_list)

for i in range(K):
    if i >= sort_h_list_length:
        break
    sort_h_list.pop(0)

print(sum(sort_h_list))

### FIXED CODE ###

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

sort_h_list = sorted(h_list, reverse=True)
sort_h_list_length = len(sort_h_list)

print(sum(sort_h_list[K:]))
### BUGGY CODE ###

import sys,itertools
for line in sys.stdin.readlines():
    n,s=map(int,line.strip().split())
    count=0
    for c in itertools.permutations(xrange(10),n):
        total=0
        for i in xrange(1,n+1):
            total+=i*c[i-1]
        if total==s:
            count+=1
    print count

### FIXED CODE ###

import sys
dp=[[[0]*331 for i in xrange((1<<10)+1)] for j in xrange(12)]
#dp[12][1025][331]
dp[0][0][0]=1
for i in xrange(10):
    for j in xrange(1<<10):
        for c in xrange(331):
            if dp[i][j][c]==0:
                continue
            for k in xrange(10):
                if (j>>k&1)==0:
                    dp[i+1][j|(1<<k)][(i+1)*k+c]+=dp[i][j][c]
ans=[[0]*331 for unused in xrange(12)]
for i in xrange(11):
    for j in xrange(1<<10):
        for c in xrange(331):
            ans[i][c]+=dp[i][j][c]
for line in sys.stdin.readlines():
    n,s=map(int,line.strip().split())
    if s>330:
        print 0
    else:
        print ans[n][s]
### BUGGY CODE ###

S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

S_list = [i for i in S]
def operate(i):
    global S_list
    if Q_list[i][0] == '1':
        S_list = list(reversed(S_list))
    else:
        Q_i = [k for k in Q_list[i][2]]
        if Q_list[i][1] == '1':
            S_list = Q_i + S_list
        else:
            S_list = S_list + Q_i
 
for i in range(Q):
    operate(i)
print(''.join(S_list))

### FIXED CODE ###

S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))
### BUGGY CODE ###

n,m,d = (int(i) for i in input().split())
step = n-d
if d != 0:
  step =step*2
print('{:.10f}'.format(step*n**(m-2)*(m-1)/n**m))


### FIXED CODE ###

n,m,d = (int(i) for i in input().split())
step = n-d
if d != 0:
  step =step*2
print('{:.10f}'.format(step*(m-1)/n**2))
### BUGGY CODE ###

# coding: utf-8


def main():
    n, m = map(int, raw_input().split())

    l = [map(int, raw_input().split()) for _ in xrange(m)]

    la = [ab[0] for ab in l if ab[1] == n]

    for ab in l:
        if ab[0] == 1 and ab[1] in la:
            print "POSSIBLE"
            return

    print "IMPOSSIBLE"

main()


### FIXED CODE ###

# coding: utf-8


def main():
    n, m = map(int, raw_input().split())

    s = [0] * 200010
    t = [0] * 200010
    for _ in xrange(m):
        a, b = map(int, raw_input().split())
        if a == 1:
            s[b] = True
        if b == n:
            t[a] = True

    for i in xrange(1, n+1):
        if s[i] and t[i]:
            print "POSSIBLE"
            return

    print "IMPOSSIBLE"

main()
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [0] * n
c[0] = 0
for i in range(1, min(n, k + 1)):
    c[i] = abs(h[i] - h[0])

for i in range(2, n):
    c[i] = c[i - 1] + abs(h[i] - h[i - 1])
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        c[i] = min(c[i], c[i - j] + abs(h[i] - h[i - j]))

print(c[n - 1])


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
c = [float("INF")] * n
c[0] = 0
for i in range(1, n):
    for j in range(1, min(n, k + 1)):
        c[i] = min(c[i], c[i - j] + abs(h[i] - h[i - j]))

print(c[n - 1])
### BUGGY CODE ###

import numpy as np


N = [int(i) for i in input().split()][0]
array = np.zeros([N, 26])
string = list(input())
strs = []
a0 = ord("a")
for n, s in enumerate(string):
  i = ord(s) - a0
  array[n, i] = 1
  strs.append(i)
qumsum = np.cumsum(array, axis=0)

Q = [int(i) for i in input().split()][0]
queries =[[i for i in input().split()] for _ in range(Q)]

changed = []
for que in queries:
  type_, pos, st = que
  if type_ == "1":
    p = int(pos) - 1
    s1 = strs[p]
    array[p, s1] = 0
    s2 = ord(st) - a0
    strs[p] = s2
    array[p, s2] = 1
    qumsum[p:, s1] -= 1
    qumsum[p:, s2] += 1
#    changed.append((p, s1, s2))
  else:
    lq = int(pos) - 1
    rq = int(st)
    sums = qumsum[rq-1, :] - qumsum[lq, :] + array[lq, :]
    print(np.sum(sums>0))



### FIXED CODE ###



N = [int(i) for i in input().split()][0]
string = list(input())
Q = [int(i) for i in input().split()][0]
queries = [[i for i in input().split()] for _ in range(Q)]

tmp = N 
c = 0
while tmp > 0:
  c += 1
  tmp //= 2
N2 = 2**c
offset = N2 - 1

seg_tree = [0 for _ in range(N2*2 -1)]
for n in range(N):
  ind = ord(string[n]) - ord("a")
  seg_tree[offset + n] = 1 << ind

def set_seg_tree(i, seg_trees):
  if i >= N2 -1:
    return seg_trees[i]
  left = 2*i + 1
  right = 2*i + 2
  l_seg = set_seg_tree(left, seg_trees)
  r_seg = set_seg_tree(right, seg_trees)
  seg_trees[i] = l_seg | r_seg
  return seg_trees[i]
set_seg_tree(0, seg_tree)
    
def update(i, c, seg_trees):
  i += offset
  seg_trees[i] = 1 << c
  while i > 0:
    i = (i - 1)//2
    seg_trees[i] = seg_trees[i * 2 + 1] | seg_trees[i * 2 + 2]

def get_sum(a, b, k, l, r, seg_trees):
  if (b <= l) or (r <= a):
    return 0
  if (a <= l) and (r <= b):
    return seg_trees[k]
  vl = get_sum(a, b, k * 2 + 1, l, (l + r)//2, seg_trees)
  vr = get_sum(a, b, k * 2 + 2, (l + r)//2, r, seg_trees)
  return vl | vr

for query in queries:
  type_, i, q = query
  if type_ == "1":
    i = int(i) - 1
    pos = ord(q) - ord("a")
    update(i, pos, seg_tree)
  else:
    l = int(i) - 1
    r = int(q)
    ret = get_sum(l, r, 0, 0, N2, seg_tree)
    print(bin(ret).count("1"))
### BUGGY CODE ###

from itertools import accumulate
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))

P = [(i+1)/2 for i in p]
ans = max([sum(P[i:i+k]) for i in range(n-k+1)])

print(ans)

### FIXED CODE ###

from itertools import accumulate
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))

P = list(accumulate([(i+1)/2 for i in p]))
P = [0] + P
ans = max([P[i+k]-P[i] for i in range(n-k+1)])
print(ans)
### BUGGY CODE ###

n = int(input())

lst = list(map(int, input().split()))
lst = sorted(lst, reverse=True)
class Queue:
  def __init__(self):
    self.queue_lst = []
    self.first_flag = True
    self.count = 0
  
  def add(self, friend_val):
    if self.first_flag:
      self.queue_lst.append(friend_val)
      self.first_flag = False
    else:
      self.queue_lst.append(friend_val)
      self.queue_lst.append(friend_val)
      self.count += self.queue_lst.pop(0)
  
queue = Queue()

for i in lst:
  queue.add(i)



print(queue.count)

### FIXED CODE ###

n = int(input())

lst = list(map(int, input().split()))
lst = sorted(lst, reverse=True)
class Queue:
  def __init__(self):
    self.queue_lst = []
    self.first_flag = True
    self.count = 0
    self.index = 0
  
  def add(self, friend_val):
    if self.first_flag:
      self.queue_lst.append(friend_val)
      self.first_flag = False
    else:
      self.queue_lst.append(friend_val)
      self.queue_lst.append(friend_val)
      self.count += self.queue_lst[self.index]
      self.index += 1
  
queue = Queue()

for i in lst:
  queue.add(i)



print(queue.count)
### BUGGY CODE ###

S = input()
ans = 0

for i in range(len(S)):
    for j in range(i, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1

print(ans)

### FIXED CODE ###

p=d=2019
z=[0]*p
for i,j in enumerate(input()[::-1]):
	d=d+int(j)*pow(10,i,p)
	z[d%p]+=1
r=z[0]
for i in z:
	r+=i*(i-1)//2
print(r)
### BUGGY CODE ###

import math
from functools import reduce

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

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)

print(ans)

### FIXED CODE ###

import math

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    h,w = map(int,input().split())
    a = [list(map(int,input().split())) for i in range(h)]
    b = [list(map(int,input().split())) for i in range(h)]

    dp = [[[False]*4000 for j in range(w)] for i in range(h)]

    dp[0][0][2000+a[0][0]-b[0][0]] = True
    dp[0][0][2000-a[0][0]+b[0][0]] = True


    for i in range(1,h):
        for k in range(4000):
            if 0 <= k+a[i][0]-b[i][0] <= 3999 and dp[i-1][0][k+a[i][0]-b[i][0]]:
                dp[i][0][k] = True
            elif 0 <= k-a[i][0]+b[i][0] <= 3999 and dp[i-1][0][k-a[i][0]+b[i][0]]:
                dp[i][0][k] = True

    for j in range(1,w):
        for k in range(4000):
            if 0 <= k+a[0][j]-b[0][j] <= 3999 and dp[0][j-1][k+a[0][j]-b[0][j]]:
                dp[0][j][k] = True
            elif 0 <= k-a[0][j]+b[0][j] <= 3999 and dp[0][j-1][k-a[0][j]+b[0][j]]:
                dp[0][j][k] = True       


    for i in range(1,h):
        for j in range(1,w):
            for k in range(4000):
                if 0 <= k+a[i][j]-b[i][j] <= 3999 and dp[i-1][j][k+a[i][j]-b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k+a[i][j]-b[i][j] <= 3999 and dp[i][j-1][k+a[i][j]-b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k-a[i][j]+b[i][j] <= 3999 and dp[i-1][j][k-a[i][j]+b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k-a[i][j]+b[i][j] <= 3999 and dp[i][j-1][k-a[i][j]+b[i][j]]:
                    dp[i][j][k] = True

    res = 10**9
    for k in range(4000):
        if dp[-1][-1][k]:
            res = min(res,abs(2000-k))

    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

h,w =map(int,input().split())
a = [tuple(map(int,input().split())) for _ in [0]*h]
b = [tuple(map(int,input().split())) for _ in [0]*h]


mid = 1<<(80*160)
dp = [[0]*w for _ in [0]*h]

for i in range(h):
    for j in range(w):
        diff = abs(a[i][j]-b[i][j])
        new = 0
        if i > 0:
            new |= dp[i-1][j]
        if j > 0:
            new |= dp[i][j-1]
        if (i,j) == (0,0):
            new = mid
        dp[i][j] = (new<<diff)|(new>>diff)


res = 10**9
p = dp[-1][-1]
for i in range(80*321):
    if p&1 == 1:
        res = min(res,abs(80*160-i))
    p = p>> 1
print(res)
### BUGGY CODE ###

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

def f(A):
  D=[0]*(N+1)
  for j in range(N):
    d=A[j]
    mi=max(j-A[j],0)
    ma=min(j+A[j],N-1)
    D[mi]+=1
    D[ma+1]-=1   
  for j in range(1,N):
    D[j]+=D[j-1]
  A=D
  return A 

for i in range(K):
  D=f(A)
  A=D
  if A==[N]*(N+1):
    break
print(*A[:-1])

### FIXED CODE ###

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

def f(A):
  D=[0]*(N+1)
  for j in range(N):
    mi=max(j-A[j],0)
    ma=min(j+A[j],N-1)
    D[mi]+=1
    D[ma+1]-=1   
  for i in range(1,N):
    D[i]+=D[i-1]
  A=D[:-1]
  return A 

for i in range(min(K,42)):
  A=f(A)
print(*A)
### BUGGY CODE ###

n=int(input())
s=input()
dp=[n*[0]for _ in range(n)]
for i in range(n):
  if s[i]==s[0]:
    dp[i][0]=dp[0][i]=1
for i in range(1,n):
  for j in range(1,n):
    if s[i]==s[j]:
      dp[i][j]=dp[i-1][j-1]+1
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if i<j-dp[i][j]+1:ans=max(ans,dp[i][j])
print(ans)

### FIXED CODE ###

n=int(input())
s=list(map(ord,list(input())))
dp=[n*[0]for _ in range(n)]
for i in range(n):
  if s[i]==s[0]:
    dp[i][0]=dp[0][i]=1
for i in range(1,n):
  for j in range(1,n):
    if s[i]==s[j]:
      dp[i][j]=dp[i-1][j-1]+1
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if i<j-dp[i][j]+1:ans=max(ans,dp[i][j])
print(ans)
### BUGGY CODE ###

#解説参照
#状態拡張、方向転換を切り上げで表現
h,w,k=map(int, input().split())
x1,y1,x2,y2=map(int, input().split())
x1-=1;y1-=1;x2-=1;y2-=1
c=[input() for _ in range(h)]
INF=10**15
dp=[[[INF]*4 for _ in range(w)] for _ in range(h)]
dp[x1][y1]=[0]*4
from collections import deque
q=deque()

for i in range(4):q.append((x1,y1,i))
dxy=[(1,0),(0,1),(-1,0),(0,-1)]

while q:
    x,y,i=q.popleft()
    for j,(dx,dy) in enumerate(dxy):
        if i!=j and dp[x][y][j]>((dp[x][y][i]+k-1)//k)*k:
            dp[x][y][j]=((dp[x][y][i]+k-1)//k)*k
            q.append((x,y,j))
        xd=x+dx;yd=y+dy
        if 0<=xd and  xd<h and 0<=yd and yd<w:
            if c[xd][yd]!='@':
                if i==j and dp[xd][yd][i]>dp[x][y][i]+1:
                    dp[xd][yd][i]=dp[x][y][i]+1
                    q.append((xd,yd,i))
            
if min(dp[x2][y2])==INF:
    print(-1)
else:
    print((min(dp[x2][y2])+k-1)//k)

### FIXED CODE ###

import sys
input = sys.stdin.readline

h,w,k=map(int, input().split())
x1,y1,x2,y2=map(int, input().split())
x1-=1;y1-=1;x2-=1;y2-=1
c=[input() for _ in range(h)]
INF=10**14
dp=[[INF for _ in range(w)] for _ in range(h)]
dp[x1][y1]=0
from collections import deque
q=deque()

q.append((x1,y1))
dxy=[(1,0),(0,1),(-1,0),(0,-1)]

while q:
    x,y=q.popleft()
    for dx,dy in dxy:
        for j in range(1,k+1):
            if not 0<=x+dx*j<h:break
            if not 0<=y+dy*j<w:break
            if c[x+dx*j][y+dy*j]=='@':break
            if dp[x+dx*j][y+dy*j]>dp[x][y]+1:
                dp[x+dx*j][y+dy*j]=dp[x][y]+1
                q.append((x+dx*j,y+dy*j))
            elif dp[x+dx*j][y+dy*j]==dp[x][y]+1:continue###
            elif dp[x+dx*j][y+dy*j]<=dp[x][y]:break###
    
            
            if x+dx*j==x2 and y+dy*j==y2:
                print(dp[x2][y2])
                exit()

        
print(-1)
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1-r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)
### BUGGY CODE ###

N = int(input())
S = input()
#dp[i][j] S[i-x:i+1]==S[j-x:j+1]となる最大のx
dp = [[0] * (N + 1) for _ in range(N + 1)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i)
    ans = max(dp[i] + [ans])
print(ans)


### FIXED CODE ###

import itertools
N = int(input())
S = input()
dp = [[0] * N for _ in range(N)]
ans = 0
for i, j in itertools.combinations(range(N), 2):
    if S[i] == S[j]:
        dp[i][j] = dp[i - 1][j - 1] + 1
    else:
        dp[i][j] = 0
    ans = max(ans, min(j - i, dp[i][j]))
print(ans)