Harryxun/stf_run huggingface dataset:
def resolve():
    N, M = map(int, input().split())

    person_group = [0] * (N+5)
    group_counter = 0
    member_counter = {0: 0}

    def _marge_group(a, b):
        for i in range(len(person_group)):
            if person_group[i] == b:
                person_group[i] == a
        member_counter[a] += member_counter.pop(b)

    for _ in range(M):
        A, B = map(int, input().split())
        if person_group[A] == 0 and person_group[B] == 0:
            group_counter += 1
            person_group[A] = group_counter
            person_group[B] = group_counter
            member_counter[group_counter] = 2
        elif person_group[A] != 0 and person_group[B] == 0:
            person_group[B] = person_group[A]
            member_counter[person_group[A]] += 1
        elif person_group[A] == 0 and person_group[B] != 0:
            person_group[A] = person_group[B]
            member_counter[person_group[B]] += 1
        else:
            if person_group[A] == person_group[B]:
                continue
            else:
                _marge_group(person_group[A], person_group[B])
    print(max(member_counter.values()))

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

class UnionFind():
    def __init__(self, n: int):
        """
        n: ノード数
        """
        self.n = n
        """
        d: UnionFind木のデータ構造
            各要素の根要素を格納するリスト
            根要素の場合は, グループの要素数*-1を格納する
        """
        self.d = [-1] * n

    def find(self, x: int) -> int:
        """
        要素xが属するグループの根を返す
        """
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]

    def unite(self, x: int, y: int) -> bool:
        """
        要素xが属するグループと, 要素yが属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x: int, y: int) -> bool:
        """
        要素x, yが同じグループに属するかどうかを返す
        """
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        """
        要素xが属するグループのサイズ(要素数)を返す
        """
        return -self.d[self.find(x)]

    def members(self, x: int) -> list:
        """
        要素xが属するグループの要素をリストで返す
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def groups(self) -> list:
        """
        すべての根の要素をリストで返す
        """
        return [i for i, x in enumerate(self.d) if x < 0]

    def group_count(self) -> int:
        """
        グループの数を返す
        """
        return len(self.groups())


def resolve():
    N, M = map(int, input().split())

    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(int, input().split())
        uf.unite(A-1, B-1)

    ans = 0
    for i in uf.groups():
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == "__main__":
    resolve()
x = input() y = input() z = input()
print(z) print(x) print(y)

### FIXED CODE ###

x,y,z = map(int,input().split())

print(z,x,y)
n = int(input())
p=3.142
print(2*n*p)

### FIXED CODE ###

n,m=map(int, input().split())
A = list(map(int, input().split()))
if n-sum(A)<0:
    print(-1)
    exit()

print(n-sum(A))
def main():
    import sy
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    n,k = ina()
    tmp = [[] for _ in range(n)]
    for _ in range(n-1):
        x,x1=  ina()
        x-=1
        x1-=1
        tmp[x].append(x1)
        tmp[x1].append(x)
    def dfs(teiru,ta):
        rick = 1
        coulduse = k-1 if ta==-1 else k-2
        for i in tmp[teiru]:
            if i == ta:
                continue
            rick*=coulduse
            rick%=1000000007
            coulduse-=1
            rick*=dfs(i,teiru) 
            rick%=1000000007
        return rick
    print(k*dfs(0,-1)%1000000007)
    

    


        
        
        


    
        


        


    




















if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(311111)
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    n,k = ina()
    tmp = [[] for _ in range(n)]
    for _ in range(n-1):
        x,x1=  ina()
        x-=1
        x1-=1
        tmp[x].append(x1)
        tmp[x1].append(x)
    def dfs(teiru,ta):
        rick = 1
        coulduse = k-1 if ta==-1 else k-2
        for i in tmp[teiru]:
            if i == ta:
                continue
            rick*=coulduse
            rick%=1000000007
            coulduse-=1
            rick*=dfs(i,teiru) 
            rick%=1000000007
        return rick
    print(k*dfs(0,-1)%1000000007)
    

    


        
        
        


    
        


        


    




















if __name__ == "__main__":
    main()
a,b=map(int,input().split())
x=[a+b,a-b,a*b]
print(max(a))


### FIXED CODE ###

a,b=map(int,input().split())
x=[a+b,a-b,a*b]
print(max(x))
A,B,H,M=input().split()

A=int(A)
B=int(B)
H=int(H)
M=int(M)

kakudo_H = H*30 +M*0.5
kakudo_M = M*6
if M==0:
    kakudo_M=360

kakudo_sa=abs(kakudo_H-kakudo_M)
# cはまずは2条している値としてセット
c=A**2 +B**2-2*A*B*(math.cos(math.radians(kakudo_sa)))
C=c**0.5
print(C)

### FIXED CODE ###

import math
A,B,H,M=input().split()

A=int(A)
B=int(B)
H=int(H)
M=int(M)

kakudo_H = H*30 +M*0.5
kakudo_M = M*6
if M==0:
    kakudo_M=360

kakudo_sa=abs(kakudo_H-kakudo_M)
# cはまずは2条している値としてセット
c=A**2 +B**2-2*A*B*(math.cos(math.radians(kakudo_sa)))
C=c**0.5
print(C)
from bisect import *
N,M=map(int,input().split())
kagi=[]
for i in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    for i in range(b):
        C[i]-=1
    kagi.append([a,set(C)])

value=10**7
idx=-1
for i in range(M):
    if 0 in kagi[i][1] and kagi[i][0]<value:
        value=kagi[i][0]
        idx=i
if idx==-1:
    print(-1)
    exit()
kagilst=[idx]

takara=[set() for i in range(N)]
for m in range(M):
    for k in kagi[m][1]:
        takara[k].add(m)

for n in range(1,N):
    """if [k for k in kagilst if n in kagi[k][1]]:
        continue"""
    tempvalue=10**7
    for i in range(len(kagilst)**2):

        for k in takara[n]:
            lst=[0 for x in range(n)]
            for z in kagilst+[k]:
                for m in kagi[z][1]:
                    if m<len(lst):
                        lst[m]=1
            A=bin(i)[:2]
            A=list(reversed(list(A)))
            for i in range(len(A)-len(kagilst)):
                A.append("0")
            for a in range(len(kagilst)):

                if A[a]=="1":
                    for h in kagi[kagilst[a]][1]:
                        if h<len(lst):
                            lst[h]=1
            if not 0 in lst:
                temptempvalue=value+sum([kagi[a][0] for a in range(len(kagilst)) if A[a]=="1"])+kagi[k][0]
                if temptempvalue<tempvalue:
                    tempvalue=temptempvalue
                    tempkagi=k

    if tempvalue==10**7:
        print(-1)
        exit()
    value=tempvalue
    kagilst.append(k)
print(value)


### FIXED CODE ###

from bisect import *
N,M=map(int,input().split())
kagi=[]
for i in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    value=0
    for i in range(b):
        C[i]-=1
        value+=2**C[i]

    kagi.append([a,value])


dp=[[10**8 for i in range(2**N)] for m in range(M+1)]
dp[0][0]=0
for i in range(M):
    for s in range(2**N):
        dp[i+1][s]=min(dp[i][s],dp[i+1][s])
        dp[i+1][s|kagi[i][1]]=min(dp[i+1][s|kagi[i][1]],dp[i][s]+kagi[i][0])
if 10**8==dp[M][-1]:
    print(-1)
else:
    print(dp[M][-1])
import numpy as np

S = np.array(list(map(int, list(input()))))
q, r = len(S) // 2, len(S) % 2
a1 = np.array([1, 0] * q + [1] * r)  # 1010...01 (偶数長なら 1010...10)
a2 = np.array([0, 1] * q + [0] * r)  # 1010...01 (偶数長なら 1010...10)

print(min(sum(abs(a1 - S)), sum(abs(a2 - S))))

### FIXED CODE ###

S = list(input())

dist1 = 0  # 1010...01 との編集距離
dist2 = 0  # 0101...10 との編集距離
for i, s in enumerate(S):
    if i % 2 == 1:
        if s == '1':
            dist2 += 1
        else:
            dist1 += 1
    if i % 2 == 0:
        if s == '1':
            dist1 += 1
        else:
            dist2 += 1

print(min(dist1, dist2))
import numpy as np


n,d=map(int,input().split())
x=[]
X=[]
cnn=0
for i in range(n):
    x=input().split()
    x=[int(i) for i in x]
    X.append(x)

for i in range(n-1):
    for j in range(n-i,n,1):
        a=np.array(X[i])
        b=np.array(X[i+1])
        u=b-a
        if u==int(u):
            cnn+=1
print(cnn)

### FIXED CODE ###

import numpy as np


n,d=map(int,input().split())
x=[]
cnt=0
X=[]
for i in range(n):
    x=input().split()
    x=[int(i) for i in x]
    X.append(x)


for i in range(n,0,-1):
    for j in range(i-1,0,-1):
        a=np.array(X[i-1])
        b=np.array(X[j-1])
        u=b-a
        u=np.linalg.norm(u)
        if(int(u)==u):
            cnt+=1

        
print(cnt)
n=int(input())

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

for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][2]>0:
				h=x[k][2]+abs(i-x[k][0])+abs(j-x[k][1])
			break
		chk=0
		for k in range(n): 
			if x[k][2]!=max(h-abs(i-x[k][0])-abs(j-x[k][1]),0):
				chk=1
				break
		if chk==0:
			res=[i,j,h]
			break
	if chk==0:
		break

print(*res)


### FIXED CODE ###

n=int(input())

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

for i in range(101):
	for j in range(101):
		for k in range(n):
			if x[k][2]>0:
				h=x[k][2]+abs(i-x[k][0])+abs(j-x[k][1])
				break
		chk=0
		for k in range(n): 
			if x[k][2]!=max(h-abs(i-x[k][0])-abs(j-x[k][1]),0):
				chk=1
				break
		if chk==0:
			res=[i,j,h]
			break
	if chk==0:
		break

print(*res)
from math import gcd, floor
A, B, C, D = map(int, input().split())
lcm = int((C*D) / gcd(C, D))
anti_b = B - (floor(B/C) + floor(B/D) - floor(B/lcm))
anti_a = (A-1) - (floor((A-1)/C) + floor((A-1)/D) - floor((A-1)/lcm))
print(anti_b-anti_a)


### FIXED CODE ###

from fractions import gcd
A, B, C, D = map(int, input().split())
lcm = int((C*D) / gcd(C, D))
print((B - (B//C + B//D - B//lcm)) -
      ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)))
import itertools
import math 

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

def divisor(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
"""
if is_prime(a) and is_prime(b):
    print(1)
    import sys
    sys.exit()
"""

a_L = divisor(a)
b_L = divisor(b)

kouyaku = set(a_L) & set(b_L)

new_L = []


for val in kouyaku:
    if is_prime(val):
        new_L.append(val)


new_L.append(1)
print(len(new_L))


### FIXED CODE ###

n = int(input())

L = []

import sys
if n ==0:
    print(0.0)
    sys.exit()

for val in range(n+1):
    if val % 2 ==1:
        L.append(val)
print(len(L)/n)
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = b-a+1
    c_max = b+a-1
    l = bisect.bisect_left(Ls,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(Ls,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)


### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = L_2nd-L_1st+1
    c_max = L_2nd+L_1st-1
    l = bisect.bisect_left(L,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(L,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)
def main():
    s = input()
    s_ = list(set(s))
    if s.count(s_[0]) == 2 and len(s_) == 2i:
        print('Yes')
    else:
        print('No')
   

if __name__ == "__main__":
    main()


### FIXED CODE ###


def main():
    s = input()
    s_ = list(set(s))
    if s.count(s_[0]) == 2 and len(s_) == 2:
        print('Yes')
    else:
        print('No')
   

if __name__ == "__main__":
    main()
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0

for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1]:
  print((l*K)//2)
  sys.exit()

if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1


ans = 0

for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)

### FIXED CODE ###

import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0
 
for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1] or l ==1:
  print((l*K)//2)
  sys.exit()
  
if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1
 
 
ans = 0
 
for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)
import math

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

print(str((a * b) // math.gcd(a, b)))


### FIXED CODE ###


def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z



def lcm(m,n):
    return int(m * n/gcd(m,n))

a,b = map(int,input().split())
print(lcm(a,b))
import bisect
N,K = map(int,input().split())
D = list(map(int,input().split()))
num = {0,1,2,3,4,5,6,7,8,9}
Ds = set(D)
diff = num^Ds
if 0 in diff:
    diff.remove(0)
    lenn = len(str(N))
    print(str(min(diff)) + '0'*(lenn-1))
else:
    lenn = len(str(N))
    diff = list(diff)
    diff.sort()
    strN = str(N)
    for i in range(lenn):
        intN = int(strN[i])
        ind = bisect.bisect_left(diff,intN)
        print(diff[ind],end='')


### FIXED CODE ###

N,K = map(int,input().split())
D = input().split()
num = set([str(i) for i in range(10)])
Ds = set(D)
diff = num^Ds
ans = N
while True:
    strN = set(list(str(ans)))
    if strN - diff:
        ans += 1
    else:
        break
print(ans)
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, K = LI()
A = LI()

tel = [-1] * N

i = 0
time = 1
while True:
    # print(i, end=" ")
    if time == K:
        print(A[i])
        break
    
    if tel[i] == -1:
        tel[i] = [time, A[i]-1]
        i = A[i]-1
    else:
        # i = A[i]-1
        break
    
    time += 1
    # print(time, tel)
# print()
# print(time-1)
# print(time - tel[i][0])
# print((K - (time-1)) % (time - tel[i][0]))

for _ in range((K - (time-1)) % (time - tel[i][0])):
    i = A[i]-1

print(i+1)


### FIXED CODE ###

# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, K = LI()
A = LI()

tel = [-1] * N
flag = True
i = 0
time = 1
while True:
    # print(i, end=" ")
    if time == K:
        print(A[i])
        flag = False
        break
    
    if tel[i] == -1:
        tel[i] = [time, A[i]-1]
        i = A[i]-1
    else:
        # i = A[i]-1
        break
        # pass
    
    time += 1
    # print(time, tel)
# print()
# print(time-1)
# print(time - tel[i][0])
# print((K - (time-1)) % (time - tel[i][0]))

if flag:
    for _ in range((K - (time-1)) % (time - tel[i][0])):
        i = A[i]-1

    print(i+1)
a=input()
print(a+a*a+a*a*a)

### FIXED CODE ###

num = int(input())
num2 = num + num*num+num*num*num
print(num2)
z=int(input())

def solv_quadratic_equation(a, b, c):
  """ 2次方程式を解く  """
  D = (b**2 - 4*a*c) ** (1/2)
  x_1 = (-b + D) / (2 * a)
  x_2 = (-b - D) / (2 * a)

  return x_1,x_2

ans=0

i=1

# print(10**15)

# a,b=solv_quadratic_equation(1,1,1000000000000000)

# print(a,b)

while True:

  a,b=solv_quadratic_equation(1,1,-2*z*i)

  if a>=b:
    if a.is_integer():
      # print(a)
      # print(b)
      ans=a
      break
  elif a=<b:
    if b.is_integer():
      # print(a)
      # print(b)
      ans=b
      break

  i+=1

print(int(ans))


### FIXED CODE ###

def inv_gcd(a, b):
    a = (a + b) % b
    if a == 0:
        return (b, 0)
    s, t = b, a
    m0, m1 = 0, 1
 
    while t:
        u = s // t
        s -= t * u
        m0 -= m1 * u
 
        tmp = s
        s = t
        t = tmp
        tmp = m0
        m0 = m1
        m1 = tmp
    
    if m0 < 0:
        m0 += b // s
    return (s, m0)
 
 
def crt(r, m):
    n = len(r)
    r0, m0 = 0, 1
 
    for i in range(n):
        r1, m1 = (r[i] + m[i]) % m[i], m[i]
 
        if m0 < m1:
            m0, m1 = m1, m0
            r0, r1 = r1, r0
        
        if m0 % m1 == 0:
            if r0 % m1 != r1:
                return (0, 0)
            continue
        
        g, im = inv_gcd(m0, m1)
 
        u1 = m1 // g
        if (r1 - r0) % g:
            return (0, 0)
        
        x = (r1 - r0) // g % u1 * im % u1
 
        r0 += x * m0
        m0 *= u1
        if (r0 < 0):
            r0 += m0
        
    return (r0, m0)


def divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors


# print(divisors(z))

z=int(input())


ans = z-1 if z%2 else 2*z-1
for i in divisors(2*z):
  y=2*z//i
  if y == 1:
    continue
  a=[0,-1]
  b=[i,y]
  rem, mod = crt(a, b)
  #print(rem)
  #print(mod)
  if rem == mod == 0:
      continue
  ans = min(ans, rem)

print(ans if z-1 else 1)
return 'No'

### FIXED CODE ###

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

if (a == b) and (b == c):
  print('No')
elif (a == b) or (b == c) or (a == c):
  print('Yes')
else:
  print('No')
A,B=map(int,input().split())
print(A*B%100)

### FIXED CODE ###

A,B=input().split()
A=int(A)
B=round(100*float(B))
print(A*B//100)
from collections import deque


h,w=map(int,input().split())
c=list(map(int,input().split()))
d=list(map(int,input().split()))
s=[list(input()) for _ in range(h)]


for y in range(h):
    for x in range(w):
        if s[y][x]=='.':
            s[y][x]=10000000


s[c[0]-1][c[1]-1]=0
que=deque([[c[0]-1,c[1]-1]])
temp=[(1,0),(0,1),(-1,0),(0,-1),(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)]
while que:
    y,x=que.popleft()
    for i,j in temp:
        if 0<=y+i<h and 0<=x+j<w and s[y+i][x+j]!="#":
            nexty,nextx=y+i,x+j
            dist=s[nexty][nextx]
            if i*i+j*j==1 and dist>s[y][x:
                s[nexty][nextx]=s[y][x]
                que.append([nexty,nextx])
            elif dist>s[y][x]+1:
                s[nexty][nextx]=s[y][x]+1
                que.append([nexty,nextx])

if s[d[0]-1][d[1]-1]==10000000:
    print(-1)
else:
    print(s[d[0]-1][d[1]-1])


### FIXED CODE ###

from collections import deque
from sys import stdin

def bfs():
    readline=stdin.readline
    h,w=map(int,readline().split())
    sy,sx=map(int,readline().split())
    gy,gx=map(int,readline().split())
    sy-=1;sx-=1;gy-=1;gx-=1
    s=[list(readline()) for _ in range(h)]
    dict={".":10000000,"#":-1}
    s=[[dict[s[y][x]] for x in range(w)]for y in range(h)]
    s[sy][sx]=0
    que=deque([[sy,sx]])
    temp=[i for i in range(-2,3)]
    while que:
        y,x=que.popleft()
        s1=s[y][x]
        for i in temp:
            nexty=y+i
            if 0<=nexty<h:
                s2=s[nexty]
                for j in temp:
                    nextx=x+j
                    if 0<=nextx<w and s2[nextx]>=0:
                        dist=s2[nextx]
                        if i*i+j*j<=1 and dist>s1:
                            s[nexty][nextx]=s1
                            que.appendleft([nexty,nextx])
                        elif dist>s1+1:
                            s[nexty][nextx]=s1+1
                            que.append([nexty,nextx])

    if s[gy][gx]==10000000:
        print(-1)
    else:
        print(s[gy][gx])
bfs()
N, D = int(input())

print(-(-N//(2*D+1)))

### FIXED CODE ###

N, D = map(int, input().split(" "))

print(-(-N//(2*D+1)))
import sys
from bisect import bisect_right 
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [sys.stdin.readline() for i in range(A)] + [INF]
t = [-INF] + [sys.stdin.readline() for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect_right(s, x), bisect_right(t, x)
    #print(b,d)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    #print(b,d)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
import numpy as np

N = int(input())
A_u = np.cumsum(list(map(int,input().split())))
A_d = np.cumsum(list(map(int,input().split())))
ans = 0
if N == 1:
    print(A_u[0]+A_d[0])
    exit()
for i in range(N):
    if i == 0:
        ans = max(ans, A_u[i]+A[-1])
    else:
        ans = max(ans, A_u[i]+A_d[-1]-A_d[i-1])
print(ans)


### FIXED CODE ###

import numpy as np

N = int(input())
A_u = np.cumsum(list(map(int,input().split())))
A_d = np.cumsum(list(map(int,input().split())))
ans = 0
if N == 1:
    print(A_u[0]+A_d[0])
    exit()
for i in range(N):
    if i == 0:
        ans = max(ans, A_u[i]+A_d[-1])
    else:
        ans = max(ans, A_u[i]+A_d[-1]-A_d[i-1])
print(ans)
x,y,z=map(int, input().split)
print("{} {} {}".format(z,x,y))

### FIXED CODE ###

x,y,z=map(int, input().split())
print("{} {} {}".format(z,x,y))