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

import math
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in xrange(3, int(math.sqrt(n))+1, 2):
        if n%i == 0:
            return False
    return True

n = input()
for _ in xrange(n):
    s = 0
    a, b = map(int, raw_input().split())
    for i in xrange(a, b+1):
        if is_prime(i) and is_prime((i+1)/2):
            s += 1
    print s


### FIXED CODE ###

import math
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in xrange(3, int(math.sqrt(n))+1, 2):
        if n%i == 0:
            return False
    return True

m = list()
s = 0
for i in xrange(10**5):
    if is_prime(i) and is_prime((i+1)/2):
        s += 1
    m.append(s)

n = input()
for _ in xrange(n):
    s = 0
    a, b = map(int, raw_input().split())
    print m[b] - m[a-1]
### BUGGY CODE ###

N = int(input())
T, A = 1, 1
for i in range(N):
  t, a = map(int, input().split())
  i = 1
  while t * i < T or a * i < A:
    i += 1
  T = t * i
  A = a * i
print(T + A)

### FIXED CODE ###

def ceil(a, b):
  return a // b + (a % b > 0)

N = int(input())
T = A = 1
for i in range(N):
  t, a = map(int, input().split())
  m = max(ceil(T, t), ceil(A, a))
  T = t * m
  A = a * m
print(T + A)
### BUGGY CODE ###

a = int(input())
cnt = 1
count =0
for i in range(1,a):
    for j in range(1,a):
        c = i*j
        num = a-c
        if num >0:
          count +=1
        else:
          break
            
print(count)

### FIXED CODE ###

a = int(input())
cnt = 1
count =0
for i in range(1,a):
    for j in range(1,a):
        if a>i*j:
          count +=1
        else:
          break
            
print(count)
### BUGGY CODE ###

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

cnt = 0
X=[]
for n in A:
    X.append(n)
    X.append(n-1)
    X.append(n+1)

Y = set(X)

y = list(Y)

for x in y:
    transient = 0
    for a in A:
        if -1 <= a - x <= 1:
            transient += 1
    else:
        if transient > cnt:
            cnt = transient

print(cnt)


### FIXED CODE ###

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

C = [0]*(10**5 + 2)

for i in A:
    C[i-1] += 1
    C[i] += 1
    C[i+1] += 1

print(max(C))
### BUGGY CODE ###

from collections import deque

def dfs(friend, group, number, s):
    d = deque([s])
    
    while d:
        num = d.pop()
        if group[num] != 0:
            continue
        
        group[num] = number
        
        for n in friend[num]:
            d.append(n)
    
    return group
    
def main():
    n, m, k = map(int, input().split())
    
    friend = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        friend[a].append(b)
        friend[b].append(a)
    
    block = [[] for _ in range(n)]
    for _ in range(k):
        a, b = map(lambda x: int(x) - 1, input().split())
        block[a].append(b)
        block[b].append(a)
    
    group = [0] * n
    number = 1
    for i in range(n):
        if group[i] != 0:
            continue
        
        group = dfs(friend, group, number, i)
        number += 1
    
    link = []
    for i in range(number + 1):
        link.append(group.count(i))
        
    for i in range(n):
        if group[i] == 0:
            print(0, end=' ')
            continue
        ans = 0
        ans += link[group[i]]
        ans -= len(friend[i])
        for b in block[i]:
            if group[i] == group[b]:
                ans -= 1
        print(ans - 1, end=' ')
        
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n 
        self.size = [1] * n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
            
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] = self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1
                
n, m, k = map(int, input().split())
friends = [[] for _ in range(n)]
blocks = [[] for _ in range(n)]

for i in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    friends[x].append(y)
    friends[y].append(x)

for i in range(k):
    x, y = map(lambda x: int(x) - 1, input().split())
    blocks[x].append(y)
    blocks[y].append(x)

uf = UnionFind(n)
for i in range(n):
    for f in friends[i]:
        uf.union(i, f)

# 自分を除くUnionFind木の大きさ
ans = [uf.size[uf.find(i)] - 1 for i in range(n)]
# 直接的な友達を引く
for i in range(n):
    ans[i] -= len(friends[i])

for i in range(n):
    for b in blocks[i]:
        if uf.same(i, b):
            ans[i] -= 1

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

def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    def brighten(x,y):
        bright = 0
        up = x
        down = x
        right = y
        left = y
        while a[up][y] == ".":
            bright += 1
            if up == 0:
                break
            up -= 1
        while a[down][y] == ".":
            bright += 1
            if down == h-1:
                break
            down += 1
        while a[x][right] == ".":
            bright += 1
            if right == w-1:
                break
            right += 1
        while a[x][left] == ".":
            bright += 1
            if left == 0:
                break
            left -= 1
        bright -= 3
        return bright
    print
    for x in range(h):
        for y in range(w):
            if brighten(x,y) > ans:
                ans = brighten(x,y)
    print(ans)
main()

### FIXED CODE ###

def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    L = []
    R = []
    D = []
    U = []
    for x in range(h):
        L.append([])
        R.append([])
        for y in range(w):
            if a[x][y] == "#":
                L[x].append(0)
            elif y == 0:
                L[x].append(1)
            else:
                L[x].append(L[x][y-1]+1)
        for y in range(w-1,-1,-1):
            if a[x][y] == "#":
                R[x].append(0)
            elif y == w-1:
                R[x].append(1)
            else:
                R[x].append(R[x][w-y-2]+1)
        R[x].reverse()
    for y in range(w):
        D.append([])
        U.append([])
        for x in range(h):
            if a[x][y] == "#":
                U[y].append(0)
            elif x == 0:
                U[y].append(1)
            else:
                U[y].append(U[y][x-1]+1)
        for x in range(h-1,-1,-1):
            if a[x][y] == "#":
                D[y].append(0)
            elif x == h-1:
                D[y].append(1)
            else:
                D[y].append(D[y][h-x-2]+1)
        D[y].reverse()

    for x in range(h):
        for y in range(w):
            ans = max(ans, R[x][y]+L[x][y]+U[y][x]+D[y][x]-3)
            
    print(ans)
main()
### BUGGY CODE ###

import re
h,w = map(int, input().split())
m = []
for _ in range(h):
  t=[]
  
  for i in re.split("(#)", input()):
    if not i == "#":
      t.extend([len(i)-1]*len(i))
    else:
      t.append(-1)
  m.append(t)

ans=0
tate=[]
for i in range(w):
  temp = []
  cnt = 0
  for j in range(h):
    if m[j][i] == -1:
      if cnt == 0:
        temp.extend([-1])
      else:
        temp.extend([cnt-1]*(cnt))
        temp.extend([-1])
      cnt = 0
    else:
      cnt += 1
  else:
    if cnt > 0:
      temp.extend([cnt-1]*(cnt))
  tate.append(temp)
ans=0
for i in range(w):
  for j in range(h):
    if m[j][i] == -1:
      continue
    ans = max(ans,tate[i][j] + m[j][i])
print(ans + 1)

### FIXED CODE ###

import re
h,w = map(int, input().split())
m=[]
d = [[0]*w for _ in range(h)]
u = [[0]*w for _ in range(h)]
for _ in range(h):
  t=[]
  for i in re.split("(#)", input()):
    if not i == "#":
      t.extend([len(i)]*len(i))
    else:
      t.append(0)
  m.append(t)

for i in range(w):
  for j in range(h):
    if m[j][i] == 0:
      d[j][i] = 0
    else:
      if j != 0:
        d[j][i] = d[j-1][i] + 1
      else:
        d[j][i] = 1

    if m[h-1-j][i] == 0:
      u[h-1-j][i] = 0
    else:
      if h-1-j == h-1:
        u[h-1-j][i] = 1
      else:
        u[h-1-j][i] = u[h-j][i] + 1
ans=0
for i in range(w):
  for j in range(h):
    ans = max(ans, u[j][i]+d[j][i]+m[j][i])
print(ans - 2)
### BUGGY CODE ###

N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_cumsum = [0]*N

cum = 0
for i in range(N):
    cum += x_list[i]
    x_cumsum[i] = cum
    
res = cum*5 + 2*N*X
for n in range(1, N):
    res_temp = (N+n)*X
    
    for i in range(N // n):
        if i == 0:
            c = 5
        else:
            c = 2*i+3
        if N-1-(i+1)*n == -1:
            res_temp += c * x_cumsum[N-1-i*n]
        else:
            res_temp += c * (x_cumsum[N-1-i*n] - x_cumsum[N-1-(i+1)*n])
    i = N // n
    c = 2*i+3
    if N % n != 0:
        res_temp += c * x_cumsum[N % n - 1]
    res = min(res, res_temp)
    
print(res)

### FIXED CODE ###

N, X = map(int, input().split())
x_list = list(map(int, input().split()))
x_cumsum = [0]*N

cum = 0
for i in range(N):
    cum += x_list[i]
    x_cumsum[i] = cum
    
res = cum*5 + 2*N*X
for n in range(1, N):
    res_temp = (N+n)*X
    
    for i in range(N // n):
        if i == 0:
            c = 5
        else:
            c = 2*i+3
        if N-1-(i+1)*n == -1:
            res_temp += c * x_cumsum[N-1-i*n]
        else:
            res_temp += c * (x_cumsum[N-1-i*n] - x_cumsum[N-1-(i+1)*n])
    i = N // n
    c = 2*i+3
    if N % n != 0:
        res_temp += c * x_cumsum[N % n - 1]
    res = min(res, res_temp)
    
print(res)
### BUGGY CODE ###

import numpy as np


def solve():
    dp = np.zeros((R + 1, C + 1, 4), dtype=np.int64)
    for i in range(R):
        for j in range(C):
            for k in range(2, -1, -1):
                dp[i][j][k + 1] = max(
                    dp[i][j][k + 1], dp[i][j][k] + items.get((i, j), 0)
                )
            for k in range(4):
                dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
                dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
    return dp[R][C - 1][0]


R, C, K, *rcv = map(int, open(0).read().split())
items = {(r - 1, c - 1): v for r, c, v in zip(*[iter(rcv)] * 3)}
print(solve())


### FIXED CODE ###

import numpy as np
from numba import njit


@njit
def solve():
    dp = np.zeros((R + 1, C + 1, 4), dtype=np.int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                dp[i][j][k] = max(dp[i][j - 1][k], dp[i - 1][j][3])
            if items[i][j] == 0:
                continue
            for k in range(3, 0, -1):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + items[i][j])
    return dp[R][C][-1]


R, C, K, *rcv = map(int, open(0).read().split())

items = np.zeros((R + 1, C + 1), dtype=np.int32)
for r, c, v in zip(*[iter(rcv)] * 3):
    items[r][c] = v

print(solve())
### BUGGY CODE ###

def solve():
    N = int(input())
    X = input()
    X_10 = int(X,2)
    ans = []
    for i in range(N):
        if X[i] == '0':
            ans.append(f(X_10 + pow(2, N-1-i)))
        else:
            ans.append(f(X_10 - pow(2, N-1-i)))
    
    print(*ans, sep='\n')

def f(N):
    cnt = 0
    while N != 0:
        N = N % popcount(N)
        cnt += 1
    
    return cnt

def popcount(N):
    b = bin(N)
    cnt = 0
    for i in range(2,len(b)):
        if b[i] == '1':
            cnt += 1

    return cnt

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    N = int(input())
    X = input()
    X_10 = int(X,2)

    r = X.count("1")
    r0 = r-1
    r1 = r+1
    ans = []
    
    s0 = X_10 % r0 if r != 1 else None
    s1 = X_10 % r1 

    for i in range(N):
        if X[i] == '0':
            ans.append(f((s1 + pow(2,N-1-i,r1)) % r1))
        else:
            if r0 == 0:
                ans.append(0)
            else:
                ans.append(f((s0 - pow(2,N-1-i,r0)) % r0))
    
    print(*ans, sep='\n')

def f(N):
    cnt = 1
    while N != 0:
        N = N % popcount(N)
        cnt += 1
    
    return cnt

def popcount(N):
    b = bin(N)
    cnt = 0
    for i in range(2,len(b)):
        if b[i] == '1':
            cnt += 1

    return cnt

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

n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
for i in range(m):
    A[0]//=2
    A.sort(reverse=True)
print(sum(A))

### FIXED CODE ###

n,m=map(int,input().split())
import heapq

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

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a,(-1)*(-tmp_min//2))
print(-sum(a))
### BUGGY CODE ###

a,b,x=map(int,input().split())

div=a/b

from math import tan
from math import degrees
from math import pi

l=0
r=pi/2
for i in range(100000):
    mid=(l+r)/2
    t=tan(mid)
    if t<=div:
        f=a*b*b*t/2
    else:
        f=a*a/2*(2*b-a/t)
    if f<=x:
        l=mid
    else:
        r=mid

print(90-degrees(r))

### FIXED CODE ###

import math

a,b,x=map(int,input().split())

if x>=(a*a*b)/2:
    y=(2*b-2*x/(a*a))/a
    d=math.degrees(math.atan(y))
else:
    y=(a*b*b)/(2*x)
    d=math.degrees(math.atan(y))
print(d)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
a_list = LII_split()

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

ans = 0
pre_idx = -1  # 前の数字のindex

for i in range(1, N + 2):
    i_idx = -1
    for idx, x in enumerate(a_list[pre_idx+1:]):
        if x == i:
            i_idx = idx
    # print(f'{i_idx=}')
    # return
    if i_idx >= 0:
        ans += i_idx - pre_idx - 1  # 砕く数
        # if i == 1:
        #     ans -= 1
        pre_idx = i_idx
    elif i == 1:
        ans = -1
        break
    else:
        ans += N - pre_idx - 1
        break
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
a_list = LII_split()

ans = 0
# pre_idx = 0  # 前の数字のindex
current_idx = 0
continuous_cnt = 0

for i in range(1, N + 2):

    while current_idx < N:
        if a_list[current_idx] == i:
            continuous_cnt += 1
            break
        else:
            current_idx += 1
    if i == 1 and continuous_cnt == 0:
        break

print(N - continuous_cnt if continuous_cnt > 0 else -1)
### BUGGY CODE ###


k,s = map(int,input().strip().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i+l+j == s:
                count += 1
            else:
                continue

print(count)



### FIXED CODE ###

k,s = map(int,input().strip().split())
count= 0
for x in range(k+1):
    for y in range(k+1):
        if s-x-y >= 0 and s-x-y <= k:
            count += 1
        
        
print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
def lcs(s, t):
    '''s,tは文字列をリスト化したもの'''
    n = len(s)
    m = len(t)
    s.append('$')
    t.append('%')
    dp = [[-(n + m) for _j in range(m + 2)] for _i in range(n + 2)]
    dp[0][0] = 0
    for i in range(n+1):
        for j in range(m+1):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j])
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (s[i] == t[j]))
    # return dp[n][m]
    '''復元する'''
    length = dp[n][m]
    ans = ['']*(length+1)
    while(length > 0):
        if(s[n] == t[m]):
            ans[length] = s[n];
            n-=1
            m-=1
            length-=1
        elif(dp[n][m] == dp[n - 1][m]):
            n-=1
        else:
            m-=1
    return ''.join(ans)
# END CUT HERE

def ALDS1_10_C():
    q = ii()
    for _ in range(q):
        s = li()
        t = li()
        print(lcs(s, t))

def EDPC_F():
    s = li()
    t = li()
    print(lcs(s,t))


if __name__ == '__main__':
    # ALDS1_10_C()
    EDPC_F()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
def lcs(s, t):
    '''s,tは文字列をリスト化したもの'''
    n = len(s)
    m = len(t)
    s.append('$')
    t.append('%')
    dp = [[0 for _j in range(m + 2)] for _i in range(n + 2)]
    dp[0][0] = 0
    for i in range(n+1):
        for j in range(m+1):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j])
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (s[i] == t[j]))
    # return dp[n][m]
    '''復元する'''
    length = dp[n][m]
    ans = ['']*(length+1)
    while(length > 0):
        if(s[n] == t[m]):
            ans[length] = s[n]
            n-=1
            m-=1
            length-=1
        elif(dp[n+1][m+1] == dp[n][m+1]):
            n-=1
        else:
            m-=1
    return ''.join(ans[1:])
# END CUT HERE

def ALDS1_10_C():
    q = ii()
    for _ in range(q):
        s = li()
        t = li()
        print(lcs(s, t))

def EDPC_F():
    s = li()
    t = li()
    print(lcs(s,t))


if __name__ == '__main__':
    # ALDS1_10_C()
    EDPC_F()
### BUGGY CODE ###

from math import gcd

def gcd3(a, b, c):
    res = gcd(a, b)
    return gcd(res, c)


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 += gcd3(a, b, c)

print(ans)


### FIXED CODE ###

from math import gcd

K = int(input())

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(res, c)

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

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

for m in range(M):
    argmax = 0
    tmp = 0
    for n in range(len(A)):
        if A[n] >= tmp:
            argmax = n
            tmp = A[n]
    A[argmax] = int(A[argmax]/2)
res = 0
for x in A:
    res += x
print(res)


### FIXED CODE ###

from heapq import *
N, M = map(int, input().split())
A = [-int(x) for x in input().split()]
heapify(A)
for x in range(M):
    tmp = int(heappop(A)/2)
    heappush(A,tmp)
res = 0
for x in A:
    res -= x
print(res)
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    import collections

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    fp = [[10**6 for _ in range(W)] for _ in range(H)]

    que = collections.deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0
    next_y_x = [[0, 1], [1, 0], [-1, 0], [0, -1]]
    w_goto = []
    for i in range(5):
        for j in range(5):
            w_goto.append([-2 + i, -2 + j])

    is_found = False

    while que:
        temp = que.popleft()
        w_num = temp[2]

        for dy, dx in next_y_x:
            ny = temp[0] + dy
            nx = temp[1] + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1:
                if grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                    que.append([ny, nx, temp[2]])
                    fp[ny][nx] = w_num
        
        for dy, dx in w_goto:
            ny = temp[0] + dy
            nx = temp[1] + dx
            nw = w_num +1

            if 0 <= ny <= H-1 and 0 <= nx <= W-1:
                if grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                    que.append([ny, nx, nw])
                    fp[ny][nx] = nw

    if fp[Dh][Dw] != 10**6:
        print(fp[Dh][Dw])
    else:
        print(-1)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    from collections import deque

    H, W = [int(item) for item in input().split()]
    Ch, Cw = [int(item)-1 for item in input().split()]
    Dh, Dw = [int(item)-1 for item in input().split()]
    grid = [input() for _ in range(H)]
    max_num = 10**6
    fp = [[max_num] * W for _ in range(H)]

    que = deque([[Ch, Cw, 0]])
    fp[Ch][Cw] = 0

    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    while que:
        y, x, w_num = que.popleft()

        for dy, dx in walk:
            ny = y + dy
            nx = x + dx

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > w_num:
                que.appendleft([ny, nx, w_num])
                fp[ny][nx] = w_num

        for dy, dx in warp:
            ny = y + dy
            nx = x + dx
            nw = w_num +1

            if 0 <= ny <= H-1 and 0 <= nx <= W-1 and grid[ny][nx] == '.' and fp[ny][nx] > nw:
                que.append([ny, nx, nw])
                fp[ny][nx] = nw

    if fp[Dh][Dw] != max_num:
        print(fp[Dh][Dw])
    else:
        print(-1)

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

n=int(input())
a=list(map(int,input().split()))
a.sort()
ans = [1] * len(a)
index=0
for i in range(n):
    ans[index] = a.count(a[i]-1)+a.count(a[i])+a.count(a[i]+1)
    index+=1
print(max(ans))



### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
collection = Counter(a)
# print(collection)
ans = [0] * 100010
for i in collection:
    ans[i] = collection[i-1]+collection[i]+collection[i+1]
print(max(ans))
### BUGGY CODE ###

X = int(input())
for i in range(-800, 800):
    for j in range(-800, 800):
        print(i**5 - j**5)
        if i**5 - j**5 == X:            
            ans = [i, j]
            break
print(ans)

### FIXED CODE ###

X = int(input())
for i in range(-500, 500):
    for j in range(-500, 500):
        if i**5 - j**5 == X:            
            ans = [str(i), str(j)]
            break
print(" ".join(ans))