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

def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
INF=float("inf")
# from pprint import*
from collections import deque
h,w,k=LI()
x1,y1,x2,y2=LI()
x1-=1
y1-=1
x2-=1
y2-=1
# line=[list("#"*(w+2))]
# maze=line+
maze=[list(input()) for _ in range(h)]
# +line
# pprint(maze)
dist=[[INF]*(w) for _ in range(h)]

q=deque([])


# exit()
q.append((x1,y1))
dist[x1][y1]=0
while q:
    (xn,yn)=q.popleft()
    # print(xn)
    # exit()
    flg=True
    for kk in range(1,k+1):
        for i,j in [(0,-kk)]:
            if not flg:continue
            xx=xn+i
            yy=yn+j
            if (xx<0 or h<=xx) or (yy<0 or w<=yy):continue
            if maze[xx][yy]=="@":flg=False;break
            if dist[xx][yy]!=INF:continue
            dist[xx][yy]=dist[xn][yn]+1
            q.append((xx,yy))
    flg=True
    for kk in range(1,k+1):
        for i,j in [(0,+kk)]:
            if not flg:continue
            xx=xn+i
            yy=yn+j
            if (xx<0 or h<=xx) or (yy<0 or w<=yy):continue
            if maze[xx][yy]=="@":flg=False;break
            if dist[xx][yy]!=INF:continue
            dist[xx][yy]=dist[xn][yn]+1
            q.append((xx,yy))
    flg=True
    for kk in range(1,k+1):
        for i,j in [(kk,0)]:
            if not flg:continue
            xx=xn+i
            yy=yn+j
            if (xx<0 or h<=xx) or (yy<0 or w<=yy):continue
            if maze[xx][yy]=="@":flg=False;break
            if dist[xx][yy]!=INF:continue
            dist[xx][yy]=dist[xn][yn]+1
            q.append((xx,yy))
    flg=True
    for kk in range(1,k+1):
        for i,j in [(-kk,0)]:
            if not flg:continue
            xx=xn+i
            yy=yn+j
            if (xx<0 or h<=xx) or (yy<0 or w<=yy):continue
            if maze[xx][yy]=="@":flg=False;break
            if dist[xx][yy]!=INF:continue
            dist[xx][yy]=dist[xn][yn]+1
            q.append((xx,yy))
    
    
    
    
# pprint(maze)
# for j in dist:print(*j)
ans=dist[x2][y2]
if ans==INF:
    ans=-1
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

from collections import deque
from pprint import pprint
moves=[(0,1),(1,0),(0,-1),(-1,0)]
pp=pprint
# INF=float("inf")

h,w,k=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())
maze=[list(input()) for _ in range(h)]
cost=[[-1]*w for _ in range(h)]

todo=deque()
todo.append((x1,y1))
cost[x1][y1]=0

while todo:
    x,y=todo.popleft()
    for vx,vy in moves:
        for kk in range(1,k+1):
            nx=x+vx*kk
            ny=y+vy*kk
            if not(0<=nx<h) or not(0<=ny<w):
                continue
            if maze[nx][ny]=="@":
                break
            if cost[nx][ny]!=-1 and cost[nx][ny]<=cost[x][y]:
                break
            if cost[nx][ny]!=-1:
                continue
            cost[nx][ny]=cost[x][y]+1
            todo.append((nx,ny))


# pp(cost)
ans=cost[x2][y2]
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
cards = list(map(int, input().split()))
bc = [list(map(int, input().split()))[::-1] for _ in range(m)]
bc.sort(reverse = True)

for i in bc:
    for j in range(i[1]):
        cards.sort()
        i.sort(reverse = True)

        if cards[0] < i[0]:
            cards[0] = i[0]
            i[1] -= 1
        
        if i[1] == 0:
            i[0] = 0

print(sum(cards))

### FIXED CODE ###

n, m = map(int, input().split())
cards = [[1, int(i)] for i in input().split()]
bc = [list(map(int, input().split())) for _ in range(m)]
cards += bc
cards.sort(key = lambda x: x[1], reverse = True)

l = []
flag = 0
for i in cards:
    for j in range(i[0]):
        l.append(i[1])
        if len(l) == n:
            flag = 1
            break
    if flag:
        break

print(sum(l))
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 100000000000000000

for i in range(1,n):
    x = sum(li[:i])
    y = sum(li[i:])
    z = abs(x-y)
    if z < ans:
        ans = z
    
print(ans)

### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 100000000000000000

for i in range(1,n):
    if i == 1:
        x = sum(li[:i])
        y = sum(li[i:])
    else:
        x += li[i-1]
        y -= li[i-1]
    z = abs(x-y)
    if z < ans:
        ans = z
    
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(sorted(AB, key=lambda x: x[0], reverse=True), key=lambda x: x[1], reverse=True)
x = [0] * M
cnt = 0
cntIN = M
for a, b in AB:
    i = M-a
    while i>=0 and x[i] != 0:
        i -= 1
    else:
        if i >= 0:
            x[i] = b
            cntIN -= 1
            if cntIN <= 0:
                break

print(sum(x))


### FIXED CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True)
x = [0] * M
p = [x for x in range(M)]

cnt = 0
cntIN = M
for a, b in AB:
    i = M-a

    s = []
    while i >= 0 and p[i] != i:
        s.append(i)
        i = p[i]
    for j in s:
        p[j] = i - 1

    if i >= 0:
        x[i] = b
        p[i] = i - 1
        cntIN -= 1            
        if cntIN <= 0:
            break

print(sum(x))
### BUGGY CODE ###

n=int(input())
A=sorted(list(map(int,input().split())))
B=[0]*(1+max(A))
for i in A:
    B[i]+=1
    if B[i]==1:
        for j in range(2*i,max(A)+1,i):
            B[j]+=1
    else:
        continue
ans=0
for i in A:
  if B[i]==1: ans+=1

print(ans)

### FIXED CODE ###

n=int(input())
A=sorted(list(map(int,input().split())))
B=[0]*(1+A[-1])
for i in A:
    B[i]+=1
    if B[i]==1:
        for j in range(2*i,A[-1]+1,i):
            B[j]+=1
    else:
        continue
ans=0
for i in A:
  if B[i]==1: ans+=1

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

from functools import reduce
input()
r=reduce(lambda a,b:eval(f'{a}*{b}'),input().split())
if 10e17<r:
  print(-1)
else:
  print(r)

### FIXED CODE ###

input()
A=list(map(int,input().split()))
r=1
if 0 not in A:
  for a in A:
    r*=a
    if r>10e17:
      print(-1)
      break
  else:
    print(r)
else:
  print(0)
### BUGGY CODE ###

N, M = map(int, input().split())
v = [[] for _ in range(10**5+1)]
cities = []

for _ in range(M):
    p, y = map(int, input().split())
    cities.append([p, y])
    v[p].append(y)

for i in v:
    i.sort()

for p, y in cities:
    num = v[p].index(y) + 1
    ans = format(str(p), "0>6") + format(str(num), "0>6")
    print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
V = [[] for _ in range(N)]
ans = [0] * M

for i in range(M):
    p, y = map(int, input().split())
    V[p-1].append((y, i))

for i, v in enumerate(V, start=1):
    v.sort()
    for k, (y, j) in enumerate(v, start=1):
        ans[j] = format(str(i), "0>6") + format(str(k), "0>6")

for a in ans:
    print(a)
### BUGGY CODE ###

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 200000

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

for aa in a:
    for bb in b:
        ans = min(ans, aa + bb)

print(ans)


### FIXED CODE ###

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 200000

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)


ans = min(ans, min(a) + min(b))

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

import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7


N,Q=rl()
TT = []
now = []
for _ in range(N):
    s,t,x = rl()
    TT.append((s-x-0.5,1,x))
    TT.append((t-x-0.5,-1,x))
for i in range(Q):
    d = ri()
    TT.append((d,0,i))


TT.sort()
mx = INF
mx_f = False
ans = [-1]*Q
for st,w,x in TT:
    if w > 0:
        now.append(x)
        if mx > x:
            mx = x
            mx_f = True
    elif w < 0:
        now.remove(x)
        if mx == x:
            mx_f = False
    elif len(now) > 0:
        if not mx_f:
            mx = min(now)
            mx_f = True
        ans[x] = mx
print(*ans,sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7


N,Q=rl()
TT = []
now = set()
for _ in range(N):
    s,t,x = rl()
    TT.append((s-x-0.5,1,x))
    TT.append((t-x-0.5,-1,x))
for i in range(Q):
    d = ri()
    TT.append((d,0,i))


TT.sort()
mx = INF
mx_f = False
ans = [-1]*Q
for st,w,x in TT:
    if w > 0:
        now.add(x)
        if mx > x:
            mx = x
            mx_f = True
    elif w < 0:
        now.remove(x)
        if mx == x:
            mx_f = False
    elif len(now) > 0:
        if not mx_f:
            mx = min(now)
            mx_f = True
        ans[x] = mx
print(*ans,sep='\n')
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
ans = [0]*q
for i in range(q):
    l,r = map(int,input().split())
    ss = s[l-1:r]
    for j in range(len(ss)-1):
        if ss[j] == 'A' and ss[j+1] == 'C':
            ans[i] += 1
for i in range(q):
    print(ans[i])

### FIXED CODE ###

import bisect

n,q = map(int,input().split())
s = input()
l=[]
r=[]
a = []
c = []
for i in range(q):
    l1,r1 = map(int,input().split())
    l.append(l1)
    r.append(r1)
for i in range(n-1):
    if s[i] + s[i+1] == 'AC':
        a.append(i+1)
        c.append(i+2)
for i in range(q):
    ans = 0
    ans = bisect.bisect_right(c,r[i]) - bisect.bisect_left(a,l[i])
    print(ans)
### BUGGY CODE ###

L,R = map(int,input().split())
ans = L*(L+1)%2019

for i in range(L,R):
    for j in range(i+1,R+1):
        if (i*j)%2019 < ans:
            ans = (i*j)%2019

print(ans)

### FIXED CODE ###

l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)
### BUGGY CODE ###

n=int(input())
an=[]
an=[int(input()) for i in range(n)]
s_an=sorted(an,reverse=True)
for i in range(n):
    if max(an)==an[i]:
        print(s_an[1])
    else:
        print(max(an))

### FIXED CODE ###

n=int(input())
an=[]
an=[int(input()) for i in range(n)]
s_an=sorted(an,reverse=True)
m_an=max(an)
m_an2=s_an[1]
for i in an:
    if m_an==i:
        print(m_an2)
    else:
        print(m_an)
### BUGGY CODE ###

import numpy as np
N = int(input())
Hs = list(map(int, input().split()))
As = np.array([Hs for _ in range(N)])
h = np.array([[Hs[i]]*N for i in range(N)])
co = As + h - np.array([[abs(n-i) for i in range(N)] for n in range(N)])
ans = np.sum(co==0)
print(ans//2)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [A[i]+i for i in range(N)]
R = [i-A[i] for i in range(N)]
c = Counter(R)

ans = 0
for l in L:
    ans += c[l]

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

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

K = int(input())
q = []
r = []
for i in range(1,K+1):
    for j in range(1,K+1):
        q.append(gcd(i,j))
for i in range(1,K+1):
    for j in q:
        r.append(gcd(i,j))
print(sum(r))

### FIXED CODE ###

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

K = int(input())
q = []
r = []
for i in range(1,K+1):
    for j in range(1,K+1):
        q.append(gcd(i,j))
for i in range(1,K+1):
    for j in q:
        r.append(gcd(i,j))
print(sum(r))
### BUGGY CODE ###

s = input()
n = len(s)
#各Lについて、自分より左でもっとも右のR
n_r = [-1 for i in range(n)]
#各Rについて、自分より右でもっとも左のL
n_l = [-1 for i in range(n)]

nearest_r = 0

for i in range(n):
    if s[i] == "R":
        nearest_r = i
    else:
        n_r[i] = nearest_r

nearest_l = n-1

for i in range(n-1,-1,-1):
    if s[i] == "L":
        nearest_l = i
    else:
        n_l[i] = nearest_l

answers = [0 for i in range(n)]

for i in range(n):
    if s[i] == "R":
        if (n_l[i] - i)%2 == 0:
            answers[n_l[i]] += 1
        else:
            answers[n_l[i]-1] += 1
    else:
        if (i - n_r[i])%2 == 0:
            answers[n_r[i]] += 1
        else:
            answers[n_r[i]+1] += 1

ans  =""
for i in range(n):
    ans += str(answers[i])
    if i != n-1:
        ans += " "

print(ans)

### FIXED CODE ###

s = input()
n = len(s)
#各Lについて、自分より左でもっとも右のR
n_r = [-1 for i in range(n)]
#各Rについて、自分より右でもっとも左のL
n_l = [-1 for i in range(n)]

nearest_r = 0

for i in range(n):
    if s[i] == "R":
        nearest_r = i
    else:
        n_r[i] = nearest_r

nearest_l = n-1

for i in range(n-1,-1,-1):
    if s[i] == "L":
        nearest_l = i
    else:
        n_l[i] = nearest_l

answers = [0 for i in range(n)]

for i in range(n):
    if s[i] == "R":
        if (n_l[i] - i)%2 == 0:
            answers[n_l[i]] += 1
        else:
            answers[n_l[i]-1] += 1
    else:
        if (i - n_r[i])%2 == 0:
            answers[n_r[i]] += 1
        else:
            answers[n_r[i]+1] += 1

ans  =""
for i in range(n):
    ans += str(answers[i])
    if i != n-1:
        ans += " "

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


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

set_l = set(l)
cnt = k - len(set_l)
lst = []
for j in set_l:
    lst += [l.count(j)]
lst = sorted(lst)
print(sum(sorted(lst)[:-k]))

### FIXED CODE ###


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

set_l = set(l)
cnt = k - len(set_l)
d = [0] * 200001
for j in l:
    d[j] += 1
print(sum(sorted(d)[:-k]))
### BUGGY CODE ###

def run():
  N, K = map(int, input().split())
  ps = list(map(int, input().split()))
  dp = [0]*(N-K+1)
  dp[0] = sum(ps[0:K])
  for n in range(1, N-K+1):
    dp[n] = max(dp[n-1], sum(ps[n:n+K]))
  print((dp[-1]+K)/2)

if __name__ == '__main__':
    run()

### FIXED CODE ###

def run():
  N, K = map(int, input().split())
  ps = list(map(int, input().split()))
  dp = [0]*(N-K+1)
  ans = 0
  dp[0] = sum(ps[0:K])
  for n in range(1, N-K+1):
    dp[n] = dp[n-1]+ps[n+K-1]-ps[n-1]
  print((max(dp)+K)/2)

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

import numpy as np

N, W = map(int, input().split())

dp = np.zeros((N+1, W+1), dtype =int)

for i in range(1, N+1):
	w, v = map(int, input().split())
	for sum_w in range(1, W+1):
		if w > sum_w:
			dp[i, sum_w] = dp[i-1, sum_w]
		else:
			dp[i, sum_w] = max(dp[i-1, sum_w], dp[i-1, sum_w - w] + v)
		#print(sum_w, dp)

print(dp.max())

### FIXED CODE ###

import numpy as np

N, W = map(int, input().split())

dp = np.zeros((N+1, W+1), dtype =int)

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[i, :w] = dp[i-1, :w]
    dp[i, w:] = np.maximum( dp[i-1, w:], dp[i-1, :W+1-w] + v )

print(dp[N,:].max())
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapq.heapify(A)

    for _ in range(M):
        b, c = map(int, input().split())
        for _ in range(b):
            n = heapq.heappop(A)
            if n<c:
                heapq.heappush(A, c)
            else:
                heapq.heappush(A, n)
                break
    
    print(sum(A))
        


if __name__ == '__main__':
    main()

### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline
 
 
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    heapq.heapify(A)
 
    BC = []
    for _ in range(M):
        b, c = map(int, input().split())
        BC.append([c*(-1), b])
    heapq.heapify(BC)
    
    flg = True
    while flg:
        if len(BC)==0:
            break
        c, b = heapq.heappop(BC)
        c *= -1
        for _ in range(b):
            a = heapq.heappop(A)
            if a<c:
                heapq.heappush(A, c)
            else:
                heapq.heappush(A, a)
                flg = False
                break

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

from collections import defaultdict
from itertools import combinations


def p_e():
    N = int(input())
    S = input()

    S_idx = defaultdict(list)

    for i in range(N):
        S_idx[S[i]].append(i)

    ans = []

    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue

        comb_list = list(combinations(S_idx[c], 2))
        i = 1

        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if a + i - 1 >= N or b + i - 1 >= N:
                    comb_list.remove(comb)
                    continue

                if a + i - 1 >= b:
                    comb_list.remove(comb)
                    continue

                if S[a + i - 1] == S[b + i - 1]:
                    f = True
                else:
                    comb_list.remove(comb)

        ans.append(i - 1)

    if ans:
        print(max(ans))
    else:
        print(0)


if __name__ == '__main__':
    p_e()


### FIXED CODE ###

def p_e():
    N = int(input())
    S = input()

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


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

S = input()[::-1]

S_mod = [0] * (len(S)+1)
S_mod[0] = int(S[0])

mod_count = [0] * 2019

d = 10

#for i in range(len(S)):
#    S_mod[i] = int(S[i:len(S)])%2019

for i in range(len(S)-1):
    S_mod[i + 1] = (S_mod[i] + int(S[i+1])*d)%2019
    d *= 10
    
#print(S_mod)

for i in range(len(S_mod)):
    mod_count[S_mod[i]] += 1

#print(mod_count)
    
count = 0
for i in range(2019):
    count += mod_count[i] * (mod_count[i] - 1) / 2
    
print(int(count))

#S = list(map(int, list(input())))



### FIXED CODE ###

S = input()[::-1]

S_mod = [0] * (len(S)+1)
S_mod[0] = int(S[0])

mod_count = [0] * 2019

d = 10

#for i in range(len(S)):
#    S_mod[i] = int(S[i:len(S)])%2019

for i in range(len(S)-1):
    S_mod[i + 1] = (S_mod[i] + int(S[i+1])*d)%2019
    d = d * 10 % 2019
    
#print(S_mod)

for i in range(len(S_mod)):
    mod_count[S_mod[i]] += 1

#print(mod_count)
    
count = 0
for i in range(2019):
    count += mod_count[i] * (mod_count[i] - 1) / 2
    
print(int(count))

#S = list(map(int, list(input())))
### BUGGY CODE ###


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

def ran(num):
    count = 1
    result = ''
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result = result + str(num[i])
                count = 1
        except:
            result = result + str(num[i])
            
    # 結果をprint
    return result

print(len(ran(S)))


### FIXED CODE ###

"""
N=int(input())
L=[int(x) for x in input().split()]
L.sort()
count=0


for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[k]>=L[i]+L[j]:
                break
            count+=1
            
print(count)
"""
N=int(input())
S=input()
result=N
for i in range(N):
    if i+1==N:
        break
    
    if S[i]==S[i+1]:
        result-=1

print(result)
### BUGGY CODE ###

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

r = 0
g = 0
b = 0
for s in range(N):
    if S[s] == 'R':
        r += 1
    elif S[s] == 'G':
        g += 1
    elif S[s] == 'B':
        b += 1

ans = (r*g*b)

for i in range(N):
    for k in range(N):
        j = int((i+k)/2)
        if k <= i or (i+k)%2 != 0 or j <= i or k <= j:
            continue
        if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
            ans -= 1

print(ans)

### FIXED CODE ###

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

r = 0
g = 0
b = 0
for s in range(N):
    if S[s] == 'R':
        r += 1
    elif S[s] == 'G':
        g += 1
    elif S[s] == 'B':
        b += 1

ans = (r*g*b)

for i in range(N):
    for k in range(N):
        j = int((i+k)/2)
        if k <= i or (i+k)%2 != 0 or j <= i or k <= j:
            continue
        if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
            ans -= 1

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

class Queue:
    def enque(self, x, l):
        l.append(x)
        return l

    def deque(self, l):
        num = l[0]
        l.pop(0)
        return num

k = int(input())

queue = Queue()
l = [1,2,3,4,5,6,7,8,9]

for i in range(k):
    x = queue.deque(l)
    if x % 10 != 0:
        l = queue.enque(10*x + (x%10) -1, l)
    l = queue.enque(10*x + (x%10), l)
    if x % 10 != 9:
        l = queue.enque(10*x + (x%10) +1, l)
print(x)


### FIXED CODE ###

import queue

k = int(input())

queue = queue.Queue()
for i in range(1,10):
    queue.put(i)

for i in range(k):
    x = queue.get()
    if x % 10 != 0:
        l = queue.put(10*x + (x%10) -1)
    l = queue.put(10*x + (x%10))
    if x % 10 != 9:
        l = queue.put(10*x + (x%10) +1)
print(x)
### BUGGY CODE ###

import sys
import heapq
push = heapq.heappush
pop = heapq.heappop
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
 
H,W = map(int,readline().split())
sh,sw = map(int,readline().split())
gh,gw = map(int,readline().split())
sh,sw = sh-1,sw-1
gh,gw = gh-1,gw-1
maze = []
for _ in range(H):
    maze.append(readline().rstrip().decode())
visited = [[10**9]*W for _ in range(H)] #必要な最小ワープ回数
hp = []
push(hp,(0,sh,sw))
visited[sh][sw] = 0
while hp:
    rp,h,w = pop(hp)
    if h == gh and w == gw:
        print(rp)
        exit()
    for i in range(5):
        for j in range(5):
            if i == 2 and j == 2:
                continue
            if 0 <= h+i-2 < H and 0 <= w+j-2 < W:
                if maze[h+i-2][w+j-2] == ".":
                    if abs(i-2)+abs(j-2) <= 1:
                            if visited[h+i-2][w+j-2] > rp:
                                push(hp,(rp,h+i-2,w+j-2))
                                visited[h+i-2][w+j-2] = rp
                    else:
                        if visited[h+i-2][w+j-2] > rp+1:
                            push(hp,(rp+1,h+i-2,w+j-2))
                            visited[h+i-2][w+j-2] = rp+1
print(-1)


### FIXED CODE ###

import sys
import heapq
push = heapq.heappush
pop = heapq.heappop
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
 
H,W = map(int,readline().split())
sh,sw = map(int,readline().split())
gh,gw = map(int,readline().split())
sh,sw = sh-1,sw-1
gh,gw = gh-1,gw-1
maze = []
for _ in range(H):
    maze.append(readline().rstrip().decode())
visited = [[10**6]*W for _ in range(H)] #必要な最小ワープ回数
hp = []
push(hp,(0,sh,sw))
visited[sh][sw] = 0
while hp:
    rp,h,w = pop(hp)
    if visited[h][w] < rp:
        continue
    if h == gh and w == gw:
        print(rp)
        exit()
    for i in range(5):
        for j in range(5):
            if i == 2 and j == 2:
                continue
            if 0 <= h+i-2 < H and 0 <= w+j-2 < W:
                if maze[h+i-2][w+j-2] == ".":
                    if abs(i-2)+abs(j-2) <= 1:
                            if visited[h+i-2][w+j-2] > rp:
                                push(hp,(rp,h+i-2,w+j-2))
                                visited[h+i-2][w+j-2] = rp
                    else:
                        if visited[h+i-2][w+j-2] > rp+1:
                            push(hp,(rp+1,h+i-2,w+j-2))
                            visited[h+i-2][w+j-2] = rp+1
print(-1)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
x=1
while x<=max(a)+1:
  ans=max(ans,a.count(x-1)+a.count(x)+a.count(x+1))
  x=x+1
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
temp=[0]*(max(a)+1)
for i in range(n):
  temp[a[i]]=temp[a[i]]+1
ans=0
if max(a)==0 or max(a)==1:
  print(n)
else:
  for i in range(1,max(a)):
    ans=max(ans,temp[i-1]+temp[i]+temp[i+1])
  print(ans)