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

S = list(input())
Q = int(input())
for i in range(Q):
  q = list(input().split())
  if q[0] == '1' and len(S) > 1:
    S = S[::-1]
    
  elif q[1] == '1':
    S = [q[2]] + S
    
  else:
    S = S+[q[2]]
    
S="".join(S)
print(S)

### FIXED CODE ###

S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)
### BUGGY CODE ###

k,n=map(int,input().split())
l1=list(map(int,input().split()))
l2 = [x+k for x in l1]
l=l1+l2
ans=0
for i in range(n):
    tmpSum=0
    for j in range(n-1):
        tmpSum=max(tmpSum,l[j+1+i]-l[i])
    if ans==0:
        ans=tmpSum
    else:
        ans=min(ans,tmpSum)
print (ans)

### FIXED CODE ###

k,n,*a=map(int,open(0).read().split())
a+=[k+a[0]]
print(k-max(y-x for x,y in zip(a,a[1:])))
### BUGGY CODE ###

N = int(input())
An = input().split()
c = 0
for i in range(N):
    An[i] = int(An[i])
for i in range(N):
    for k in range(1,N-i):
        if An[0] + An[k] == k :
            c = c + 1
    del An[0]
print(c)


### FIXED CODE ###

from collections import Counter
N = int(input())
An = list(map(int,input().split()))
c = 0
Bn = []
Cn = []
for k in range(N):    
    Bn.append(An[k]+k)
    Cn.append(k-An[k])
Cj = Counter(Cn)
for i in Bn:
    c+=Cj[i]
print(c)
### BUGGY CODE ###



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

point = ["x"] * N
lis = []
notend = set([])

for i in range(N):

    lis.append([])
    notend = notend | set([i])


for i in range(M):

    L,R,D = map(int,input().split())

    lis[L-1].append([R-1,D])
    lis[R-1].append([L-1,-1 * D])

ans = "Yes"
Q = []

while True:

    if len(notend) > 0:
        Q.append(notend.pop())
    else:
        break

    nmin = 0
    nmax = 0

    while len(Q) > 0:

        q = Q.pop(0)
        if point[q] == "x":
            point[q] = 0

        for rd in lis[q]:

            #ind = bisect.bisect_left(notend,rd[0])

            #print (ind,notend,rd[0])

            if rd[0] in notend:
                notend = notend - set([rd[0]])
                point[rd[0]] = point[q] + rd[1]
                nmin = min(nmin,point[rd[0]])
                nmax = max(nmin,point[rd[0]])
                Q.append(rd[0])

            elif point[rd[0]] != point[q] + rd[1]:
                ans = "No"
                break

        if ans == "No":
            break

    if nmax - nmin > 10 ** 9:
        ans = "No"

    if  ans == "No":
        break

print (ans)


### FIXED CODE ###

from collections import deque

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

RD = [deque() for i in range(N)]
end = [False] * N

for i in range(M):

    L,R,D = map(int,input().split())
    RD[L-1].append([R-1,D])
    RD[R-1].append([L-1,-1 * D])
    end[L-1] = True
    end[R-1] = True
    
"""
    lp = wantp(L-1)
    rp = wantp(R-1)

    if lp != rp:

        if rank[lp] 
"""
    


endnum = 0
Q = deque()

cor = ["x"] * N
ans = "Yes"


for endp in range(N):

    if end[endp]:
        Q.append(endp)


        while len(Q) > 0:

            q = Q.pop()
            end[q] = False

            if cor[q] == "x":
                cor[q] = 0

            for r,d in RD[q]:

                if cor[r] == "x":
                    cor[r] = cor[q] + d
                    Q.append(r)

                elif cor[r] != cor[q] + d:
                    print ("No")
                    exit()


print ("Yes")
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))

ans = 2*10**9

for n in range(1,N):
  ans_candidate = abs(sum(a[:n])-sum(a[n:]))
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)


### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))

ans = 2*10**9
allsum = sum(a)
snukesum = 0

for n in range(1,N):
  snukesum += a[n-1]
  ans_candidate = abs(2*snukesum- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)
### BUGGY CODE ###

N = input()

ans=[0]*len(N)
distance=[]

for i in range(len(N)):
	if N[i]=="R":
		for g in range(1, len(N)):
			if N[i+g]=="L":
				distance.append(g)
				break
	else:
		for g in range(1, len(N)):
			if N[i-g]=="R":
				distance.append(g)
				break

for i in range(len(N)):
	if distance[i]%2==0:
		if N[i]=="R":
			ans[i+distance[i]]+=1
		else:
			ans[i-distance[i]]+=1
	else:
		if N[i]=="R":
			ans[i+distance[i]-1]+=1
		else:
			ans[i-distance[i]+1]+=1
print(*ans)

### FIXED CODE ###

s=input()+"R"

ans=[0]*(len(s)-1)
r_num=0
l_num=0
r_place=0
l_place=0

for i in range(1,len(s)):
    if s[i-1]=="R" and s[i]=="L":
        r_num+=1
        r_place=i-1
        l_place=i
        ans[r_place]+=r_num-r_num//2
        ans[l_place]+=r_num//2
    elif s[i-1]==s[i] and s[i-1]=="R":
        r_num+=1
    elif s[i-1]==s[i] and s[i-1]=="L":
        l_num+=1
    elif s[i-1]=="L" and s[i]=="R":
        l_num+=1
        ans[r_place]+=l_num//2
        ans[l_place]+=l_num-l_num//2
        r_num=0
        l_num=0
print(*ans)
### BUGGY CODE ###

# 解説放送の解法

INF = 1001001001

N, M = map(int, input().split())
key = []
for i in range(M):
    a, b = map(int, input().split())
    s = 0
    for c in list(map(int, input().split())):
        c -= 1
        s |= 1 << c
    key.append((s, a))

dp = [INF] * (1 << N)
dp[0] = 0
for s in range(1 << N):
    for i in range(M):
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)
        
ans = dp[-1]
if ans == INF:
    ans = -1

print(ans)

### FIXED CODE ###

# 解説放送の解法

INF = 1001001001

N, M = map(int, input().split())
key = []
for i in range(M):
    a, b = map(int, input().split())
    s = 0
    for c in list(map(int, input().split())):
        c -= 1
        s |= 1 << c
    key.append((s, a))

dp = [INF] * (1 << N)
dp[0] = 0
for s in range(1 << N):
    for i in range(M):
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)

ans = dp[-1]
if ans == INF:
    ans = -1

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

a = 10**18
N = int(input())
A = list(map(int , input().split()))
ans = 1
for i in A:
    if 0 in A:
        ans = 0
        break
    ans *= i
    if ans > a:
        ans = -1
        break
print(ans)

### FIXED CODE ###

#import functools
a = 10**18
N = int(input())
A = list(map(int , input().split()))
if 0 in A:
    ans = 0
else:
    ans = 1
for i in A:
    ans *= i
    if ans > a:
        ans = -1
        break
print(ans)
### BUGGY CODE ###

r,c,k = map(int,input().split())
dp = [[[0 for _ in range(4)] for _ in range(c+1)] for _ in range(r+1)]
g = [[0]*(c+1) for _ in range(r+1)]
for _ in range(k):
    a,b,v = map(int,input().split())
    g[a][b] = v

for i in range(r+1):
    for j in range(c+1):
        for k in range(4):
            here = dp[i][j][k]
            if i + 1 <= r:
                dp[i + 1][j][0] = max(dp[i + 1][j][0], here)
                dp[i + 1][j][1] = max(dp[i + 1][j][1], here + g[i + 1][j])
            if j + 1 <= c:
                dp[i][j + 1][k] = max(dp[i][j + 1][k], here)
                if k < 3:
                    dp[i][j + 1][k+1] = max(dp[i][j + 1][k+1], here + g[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[-1][-1][k])
print(ans)
# ans = 0
            # tmp  =dp[i][j][m]
            # if i+1<=r:
            #     dp[i+1][j][0] = max(tmp,dp[i+1][j][0])
            #     dp[i+1][j][1] = max(dp[i+1][j][1],tmp + g[i+1][j])
            # if j+1<=c:
            #     dp[i][j+1][m] = max(dp[i][j+1][m],tmp)
            #     if m<3:
            #         dp[i][j+1][m+1] = max(dp[i][j+1][m+1],tmp + g[i][j+1]) 
# print(max(dp[-1][-1]))
 

### FIXED CODE ###

import sys

R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            here = dp[k][i][j]
            if i + 1 <= R:
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
            if j + 1 <= C:
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, S: str):

    # 最短手数を求める
    DP = [INF]*(N+1)
    DP[0] = 0
    for i in range(1, N+1):
        if S[i] == "1":
            continue
        for j in range(1, M+1):
            if i-j < 0:
                break
            DP[i] = min(DP[i], DP[i-j]+1)

    if DP[-1] == INF:
        print(-1)
        return
    # 逆順に辿って実際の手を求める
    # 辞書順になるよう、後ろから貪欲に選ぶ
    ans = []
    curr = N
    while curr > 0:
        for i in range(M, 0, -1):
            if curr-i < 0:
                continue
            if curr-i == 0:
                break
            if DP[curr-i] < DP[curr]:
                break
        curr = curr - i
        ans.append(i)
    print(*reversed(ans), sep=" ")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, M, S)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, S: str):

    S = S[::-1]
    data = [0]*(N+1)
    past = 0
    for i in range(N+1):
        if S[i] == "1":
            data[i] = past
        else:
            past = i
    ans = []
    curr = 0
    while True:
        ne = curr+M
        if ne >= N:
            ans.append(N-curr)
            break
        if S[ne] == "1":
            ne = data[ne]
            if ne <= curr:
                print(-1)
                return
        ans.append(ne - curr)
        curr = ne
    print(*reversed(ans), sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, M, S)


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




N,K = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in range(N)]

"""
辺の上に点が乗っていても四角形の中に含まれると見なされるので、辺はいずれかの点の上を通るように引くと面積を小さくできる
各点のx,yをsetで持っておいて、全探索できるか？
→ N <= 50なので4つの辺の選び方が50**4、この範囲にK個以上入っているかでさらに *50なので間に合うか微妙？
小さい値で ^5 なので、間に合うかも
"""

LR = [] # left,right
TB = [] # top, bottom
for x,y in XY:
    LR.append(x)
    TB.append(y)


LR = list(set(LR))
LR.sort()
TB = list(set(TB))
TB.sort()


def more_than_K(l,r,t,b):
    cnt = 0
    for x,y in XY:
        if l <= x <= r and b <= y <= t:
            cnt += 1
    return cnt >= K

ans = float("inf")
for p in range(len(LR)):
    for q in range(p+1, len(LR)):
        for r in range(len(TB)):
            for s in range(r+1, len(TB)):

                if more_than_K(LR[p], LR[q], TB[s], TB[r]):
                    ans = min(ans, (LR[q] - LR[p]) * (TB[s] - TB[r]))


print(ans)


### FIXED CODE ###




N,K = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in range(N)]

"""
辺の上に点が乗っていても四角形の中に含まれると見なされるので、辺はいずれかの点の上を通るように引くと面積を小さくできる
各点のx,yをsetで持っておいて、全探索できるか？
→ N <= 50なので4つの辺の選び方が50**4、この範囲にK個以上入っているかでさらに *50なので間に合うか微妙？
小さい値で ^5 なので、間に合うかも
"""

LR = [] # left,right
TB = [] # top, bottom
for x,y in XY:
    LR.append(x)
    TB.append(y)


LR = list(set(LR))
LR.sort()
TB = list(set(TB))
TB.sort()


def more_than_K(l,r,t,b):
    cnt = 0
    for x,y in XY:
        if l <= x <= r and b <= y <= t:
            cnt += 1
    return cnt >= K

ans = float("inf")
for p in range(len(LR)):
    for q in range(p+1, len(LR)):
        for r in range(len(TB)):
            for s in range(r+1, len(TB)):

                if more_than_K(LR[p], LR[q], TB[s], TB[r]):
                    ans = min(ans, (LR[q] - LR[p]) * (TB[s] - TB[r]))


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

import math
from collections import Counter

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

cnt = Counter(a)
a.sort()

cand = a
ans = 0
while cand:
    p = cand[0]
    if cnt[p] == 1:
        ans += 1
    nex = []
    for num in cand:
        if num == p:
            continue
        if num % p:
            nex.append(num)
    cand = nex

print(ans)

### FIXED CODE ###

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

a.sort()
am = a[-1]

memo = [0] * (am+1)

for ai in a:
    memo[ai] = 1

p = -1

for ai in a:
    if ai == p:
        memo[ai] = 0
        continue
    for j in range(2, am // ai + 1):
        memo[ai * j] = 0
    p = ai

print(sum(memo))
### BUGGY CODE ###

import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
import numpy as np
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()

def update(a):
    b = [0]*(n+1)
    for i in range(n):
        b[max(i-a[i], 0)] +=1
        if i+a[i] <n:
            b[i+a[i]+1] -=1
    for i in range(1,n):
        b[i] += b[i-1]
    return b[:n]

end = [n]*n

for i in range(min(k, 42)):
    a = update(a)
for i in range(n):
    print(str(int(a[i]))+" ",end = "" )


### FIXED CODE ###

import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()


end = [n]*n

for i in range(min(k, 41)):
    b = [0]*(n+1)
    for j in range(n):
        b[max(j-a[j], 0)] +=1
        if j+a[j] <n:
            b[j+a[j]+1] -=1
    for j in range(1,n):
        b[j] += b[j-1]
    a = b[:n]

for i in range(n):
    print(str(int(a[i]))+" ",end = "" )
### BUGGY CODE ###

n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(n, m, k)
# print(a)
# print(b)

ans = set()
ans.add(0)

for i_n in range(0, n+1):
    if a[i_n] > k:
        break

    start_idx = max(list(ans)[-1] - i_n, 0)
    # print('start_idx', start_idx)
    for i_m in range(start_idx, m+1):
        if a[i_n] + b[i_m] > k:
            break

        time_sum = a[i_n] + b[i_m]
        # print(i_n, a[:i_n], i_m, b[:i_m], time_sum, k)
        if time_sum <= k:
            # print(i_n, a[:i_n], i_m, sum(b[:i_m]), k)
            ans.add(i_n + i_m)

# print(ans)

print(list(ans)[-1])


### FIXED CODE ###

n, m, k = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

a = [0]
b = [0]
for i in range(len(A)):
    a.append(a[i] + A[i])

for i in range(len(B)):
    b.append(b[i] + B[i])


# print(a)
# print(b)

j_n = m
ans = 0

for i_n in range(len(a)):
    if a[i_n] > k:
        break

    while b[j_n] > k - a[i_n]:
        j_n -= 1

    ans = max(ans, i_n + j_n)

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

n, m = map(int, input().split())
*a, = sorted(map(int, input().split()), key=lambda x: -x)
for i in range(m):
    tmp = a.pop(0)
    tmp //= 2
    if not a:
        a.append(tmp)
    for j in range(min(len(a), m-i)):
        if tmp > a[j]:
            a.insert(j, tmp)
            break
    else:
        a.append(tmp)

print(sum(a))

### FIXED CODE ###

import heapq, math

n, m = map(int, input().split())
*a, = map(lambda x: -int(x), input().split())
heapq.heapify(a)

for i in range(m):
    tmp = heapq.heappop(a)
    tmp = math.ceil(tmp / 2)
    heapq.heappush(a, tmp)

print(-sum(a))
### BUGGY CODE ###

N = int( input() )
c_list = []
for i in range(N):
    c_list.append( int( input() ) )
    
a = c_list[:]
a.sort()

for i in range(N):
    t = c_list[i]
    a_copy = a[:]
    a_copy.remove(t)
    print( a_copy[N - 2] )

### FIXED CODE ###

N = int( input() )
c_list = []
for i in range(N):
    c_list.append( int( input() ) )
    
a = c_list[:]
a.sort()
ma = a[ N - 1 ]

for i in range(N):
    t = c_list[i]
    if t == ma:
        print(a[N - 2])
    else:
        print(ma)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
S = [list(input()) for _ in range(h)]

ch, cw = ch - 1, cw - 1
dh, dw = dh - 1, dw - 1
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
N = [[0, 1], [0, -1], [1, 0], [-1, 0]]
P = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
     [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]

que = deque([(0, ch, cw)])
while que:
    count, y, x = que.popleft()
    if grid[y][x] < count:
        continue
    for NY, NX in N:
        if 0 <= x + NX < w and 0 <= y + NY < h and S[y + NY][x + NX] != "#":
            if grid[y + NY][x + NX] == -1 or grid[y + NY][x + NX] > count:
                grid[y + NY][x + NX] = count
                que.appendleft((count, y + NY, x + NX))
    for PY, PX in P:
        if 0 <= x + PX < w and 0 <= y + PY < h and S[y + PY][x + PX] != "#":
            if grid[y + PY][x + PX] == -1 or grid[y + PY][x + PX] > count + 1:
                grid[y + PY][x + PX] = count + 1
            que.append((count + 1, y + PY, x + PX))

print(grid[dh][dw])


### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [list(input()) for _ in range(h)]

Ch, Cw = Ch - 1, Cw - 1
Dh, Dw = Dh - 1, Dw - 1
d = [[-1] * w for _ in range(h)]
d[Ch][Cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
        [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]

que = deque([[0, Ch, Cw]])
while que:
    count, y, x = que.popleft()
    if d[y][x] < count:
        continue
    for NY, NX in walk:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count:
                d[y + NY][x + NX] = count
                que.appendleft([count, y + NY, x + NX])
    for NY, NX in warp:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count + 1:
                d[y + NY][x + NX] = count + 1
                que.append([count + 1, y + NY, x + NX])

print(d[Dh][Dw])
### BUGGY CODE ###

r, c = map(int, input().split())

cc = [input() for i in range(r)]

from collections import deque
import numpy as np

# 縦がｙ 横がx　だから座標はy,xて書く
st=[]
for i in range(r):
    for j in range(c):
        if cc[i][j]=="#":
            st.append([i,j])

# 保留スタックtodoにスタートの位置情報を入れる
todo=deque(st)
# 検知済みリストseenを-1で初期化 (何も検知してないてこと)
se=np.array([-1]*(r*c))
seen=se.reshape(r,c)

# seenにはどんだけの手数でそこに到達できるかを入れる
# 例えばスタート地点は手数0でいけるから0を入れる
for i in range(len(st)):
    seen[st[i][0],st[i][1]]=0

# 4方向の移動リスト これ使って移動していく
ido=[[1,0],[0,1],[-1,0],[0,-1]]

# 保留リストtodoが空になるまでやる
while todo:
    y, x=todo.popleft() # 現在地は保留からの先頭とりだす
    for i in range(4): # 現在地から4方向を見る
        ny, nx=y+ido[i][0], x+ido[i][1] # 現在地から隣の座標
        # 隣の座標が区画をはみ出さないかつ、検知してないときに
        if 0<=ny<r and 0<=nx<c and seen[ny, nx]==-1 and cc[ny][nx]!="#":
            # 隣に行けるということなので検知してその手数を格納
            seen[ny, nx]=seen[y,x]+1 # 手数＝前の地点の手数+1
            todo.append([ny,nx]) # 保留リストにも入れとく

print(seen.max())



### FIXED CODE ###

r, c = map(int, input().split())

cc = [input() for i in range(r)]

from collections import deque


# 縦がｙ 横がx　だから座標はy,xて書く
st=[]
for i in range(r):
    for j in range(c):
        if cc[i][j]=="#":
            st.append([i,j])

# 保留スタックtodoにスタートの位置情報を入れる
todo=deque(st)
# 検知済みリストseenを-1で初期化 (何も検知してないてこと)
seen=[[-1 for i in range(c)] for j in range(r)]

# seenにはどんだけの手数でそこに到達できるかを入れる
# 例えばスタート地点は手数0でいけるから0を入れる
for i in range(len(st)):
    seen[st[i][0]][st[i][1]]=0

# 4方向の移動リスト これ使って移動していく
ido=[[1,0],[0,1],[-1,0],[0,-1]]
m=0
# 保留リストtodoが空になるまでやる
while todo:
    y, x=todo.popleft() # 現在地は保留からの先頭とりだす
    for i in range(4): # 現在地から4方向を見る
        ny, nx=y+ido[i][0], x+ido[i][1] # 現在地から隣の座標
        # 隣の座標が区画をはみ出さないかつ、検知してないときに
        if 0<=ny<r and 0<=nx<c and seen[ny][nx]==-1 and cc[ny][nx]!="#":
            # 隣に行けるということなので検知してその手数を格納
            seen[ny][nx]=seen[y][x]+1 # 手数＝前の地点の手数+1
            todo.append([ny,nx]) # 保留リストにも入れとく
            if seen[ny][nx]>=m:
                m=seen[ny][nx]
       

print(m)
### BUGGY CODE ###

n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
while ki <= m:
    ind = prise.index(min(prise))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

### FIXED CODE ###

n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)
### BUGGY CODE ###

import numpy as np

N=int(input())
a=list(map(int,input().split()))

b=[x+1for x in a]
c=[x-1for x in a]

d=a+b+c

e=[]


for X in range(N):
    f=d.count(X)
    e.append(f)

if N==1:
    print("1")
else:
    print(max(e))

### FIXED CODE ###

from collections import Counter

N=int(input())
a=list(map(int,input().split()))

b=[x+1for x in a]
c=[x-1for x in a]

d=a+b+c

print(max(Counter(d).values()))