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

import itertools
import math
n = int(input())

for i in range(n):
    cnt = 0
    for x,y,z in itertools.product(range(1,int(math.sqrt(n))),repeat=3):
        if x**2 + y**2 + z**2 + x*y + y*z + z*x == i+1:
            cnt += 1
    print(cnt)

### FIXED CODE ###

n = int(input())
ans = [0] * n

for x in range(1,int(n**0.5)):
    for y in range(1,int(n**0.5)):
        for z in range(1,int(n**0.5)):
            a = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if a <= n:
                ans[a-1] += 1
[print(x) for x in ans]
### BUGGY CODE ###

n, m = map(int,input().split())
nei =[[i] for i in range(n)]

for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    nei[a].append(b)
    nei[b].append(a)

color = [0 for i in range(n)]
#print(nei)
def paint(v,d,c):
    if color[v] == 0:
        color[v] = c
    if d == 0:
        return
    for i in nei[v]:
        paint(i,d-1,c)

q = int(input())
vbc = [list(map(int,input().split())) for i in range(q)][::-1]

for i in range(q):
    paint(vbc[i][0]-1,vbc[i][1],vbc[i][2])
    #print(color)

for i in range(n):
    print(color[i])

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m = map(int,input().split())
nei =[[i] for i in range(n)]

for i in range(m):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    nei[a].append(b)
    nei[b].append(a)

color = [0 for i in range(n)]
depth = [-1 for i in range(n)]

def paint(v,d,c,pre):
    if d <= depth[v]:
        return
    depth[v] = d
    if color[v] == 0:
        color[v] = c
    if d == 0:
        return
    for next in nei[v]:
        if next == pre:
            continue
        paint(next,d-1,c,v)

q = int(input())
vbc = [list(map(int,input().split())) for i in range(q)][::-1]

for i in range(q):
    paint(vbc[i][0]-1,vbc[i][1],vbc[i][2],-1)
    #print(color)


for co in color:
    print(co)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
TA = []
for _ in range(N):
    TA.append(list(map(int, input().split())))

t0,a0 = 0,0
hyo = 0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        tmpt,tmpa = t,a
        if t0 > t or a0 > a:
            while t0 > tmpt or a0 > tmpa:
                tmpt += t
                tmpa += a
    t0,a0 = tmpt,tmpa
    # print(tmpt, tmpa)

print(t0+a0)



### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
TA = []
for _ in range(N):
    TA.append(list(map(int, input().split())))

t0,a0 = 0,0
for i in range(N):
    t,a = TA[i]
    if t0 == t and a0 == a:
        pass
    else:
        if t0 > t or a0 > a:
            tmp = max([t0//t + min([1, t0 % t]), a0//a + min([1, a0 % a])])
            t0 = t*tmp
            a0 = a*tmp
        else:
            t0 = t
            a0 = a

print(t0+a0)
### BUGGY CODE ###

s=input()
q=int(input())
h=0
for _  in range(q):
  d=input()
  if '2' in d:
    a,b,c=map(str,d.split())
    if b=='1':
      if h%2==0:
        s=str(c)+s
      else:
        s=s+str(c)
        
    else:
      if h%2==0:
        s=s+str(c)
      else:
        s=str(c)+s
        
  else:
    h+=1
    
if h%2==0:
  print(s)
else:
  f=list(s)
  g=list(reversed(f))
  print(''.join(g))

### FIXED CODE ###

s=input()
q=int(input())
h=0
m=''
u=''
for _  in range(q):
  d=input()
  if '2' in d:
    a,b,c=map(str,d.split())
    if b=='1':
      if h%2==0:
        m+=c
      else:
        u+=c
        
    else:
      if h%2==0:
        u+=c
      else:
        m+=c
        
  else:
    h+=1
    
M=list(m)
G=list(reversed(M))
GG=''.join(G)
s=GG+s+u
if h%2==0:
  print(s)
else:
  f=list(s)
  g=list(reversed(f))
  print(''.join(g))
### BUGGY CODE ###

import sys
import numpy as np
import math
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def judge(x,list):
  l = np.array(list) %x
  l.sort()
  aa = 0
  bb = 0
  for i in l:
    tmp = i
    if aa + tmp > K:
      bb += x-tmp
      if bb > K:
        return False
    else:
      aa += tmp
  else:
    return True

N,K = IL()
a = IL()
a.sort()
num = sum(a)
ans = []

for i in range(num,int(math.sqrt(num)-1),-1):
  if num%i == 0:
    if judge(i,a):
      ans.append(i)
    if judge(num//i,a):
      ans.append(num//i)

ans.sort()
print(ans[-1])

### FIXED CODE ###

import sys
import math
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def judge(x):
  l = []
  for i in range(N):
    l.append(a[i]%x)
  l.sort()

  aa = 0
  bb = 0
  for i in l:
    tmp = i
    if aa + tmp > K:
      bb += x-tmp
      if bb > K:
        return False
    else:
      aa += tmp
  else:
    return True

N,K = IL()
a = IL()
num = sum(a)
ans = []

for i in range(1,int(math.sqrt(num)+1)):
  if num%i == 0:
    if judge(i):
      ans.append(i)
    if judge(num//i):
      ans.append(num//i)

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

# ABC127D - Integer Cards
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
num = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
for i in lst:
    num += [i[1]] * i[0]
print(sum(sorted(num, reverse=True)[:n]))

### FIXED CODE ###

# ABC127D - Integer Cards
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
idx = 0
flg = False
for i, j in lst:
    for _ in range(i):
        if idx < n and num[idx] < j:
            ans += j
            idx += 1
        else:
            flg = True
            break
    if flg:
        break
if idx < n:
    ans += sum(num[idx:])
print(ans)
### BUGGY CODE ###

from copy import deepcopy as dcp
delta = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ds(here, lb, ub, field, count):
	result = 11
	if count == 11:
		return count
	for dx, dy in delta:
		next = (here[0]+dx,here[1]+dy)
		if ( not (lb[0] <= next[0] <= ub[0] and lb[1] <= next[1] <= ub[1]) or
		   field[next[1]][next[0]] == 1) :
		    continue
		tmp = slide(next, (dx,dy), lb, ub, dcp(field), count + 1) 
		if tmp < result:
			result = tmp
	return result

def slide(here, di, lb, ub, field, count):
	while lb[0] <= here[0] <= ub[0] and lb[1] <= here[1] <= ub[1]:
		if here == goal:
			return count
		if field[here[1]][here[0]] == 1:
			field[here[1]][here[0]] = 0
			return ds((here[0]-di[0],here[1]-di[1]), lb, ub, field, count)
		here = (here[0]+di[0],here[1]+di[1])
	else:
		return 11
while 1:
	w, h = map(int,raw_input().split(" "))
	if w == h == 0: break
	board = [[0 for _ in range(w)] for _ in range(h)]
	for j in range(h):
		inp = map(int,raw_input().split(" "))
		for i in range(w):
			tmp = inp[i]
			if tmp == 0: continue
			if tmp == 1: board[j][i] = 1
			elif tmp == 2: start = (i,j)
			else : goal = (i,j)
	count = ds(start, (0,0), (w-1,h-1), board, 0) 
	print count if count < 11 else -1

### FIXED CODE ###

delta = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ds(here, field, count, lb, ub, min_count):
	if count == min_count:
		return min_count
	ans = min_count
	for dx, dy in delta:
		nx, ny = (here[0]+dx,here[1]+dy)
		neighbor = (nx, ny)
		while lb[0] <= nx <= ub[0] and lb[1] <= ny <= ub[1]:
			if field[ny][nx] == 1:
				if (nx, ny) != neighbor:
					field[ny][nx] = 0
					ans = ds((nx-dx,ny-dy),field, count+1, lb, ub, ans)
		    		field[ny][nx] = 1
				break
			if field[ny][nx] == 3:
				if count + 1 < ans:
					ans = count + 1
				break
			nx += dx
			ny += dy
	return ans
while 1:
	w, h = map(int,raw_input().split(" "))
	if w == h == 0: break
	board = [ map(int,raw_input().split(" ")) for _ in range(h)]
	for j in range(h):
		for i in range(w):
			if board[j][i] == 2:
				start = (i,j)
	result = ds(start, board, 0, (0,0), (w-1,h-1), 11)
	print result if result < 11 else -1
### BUGGY CODE ###

import numpy as np
import collections

N = int(input())
data = list([input() for i in range(N)])

dicdata = collections.Counter(data)

newdata = [k for k, v in dicdata.items() if v == max(dicdata.values())]

newdata = sorted(newdata)

[print(i) for i in newdata]


### FIXED CODE ###

import collections

N = int(input())
data = [input() for i in range(N)]

dicdata = collections.Counter(data)

m = max(dicdata.values())

newdata = [k for k, v in dicdata.items() if v == m]

newdata.sort()

[print(i) for i in newdata]
### BUGGY CODE ###

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

count = 0

for i in range(a, b+1):
    if i % x == 0:
        count += ((b - i) // x + 1)
        break


print(count)

### FIXED CODE ###

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

print(b // x - (a - 1) // x)
### BUGGY CODE ###

L = list(map(int, input().split()))
if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
    print(0)
    exit()

if (L[0]//2)%2 == 1 and (L[1]//2)%2 == 1 and (L[2]//2)%2 == 1:
    print(-1)
    exit()

i = 0
while True:
    i += 1
    L = [L[1]//2+L[2]//2, L[0]//2+L[2]//2, L[0]//2+L[1]//2]
    if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
        print(i)
        exit()


### FIXED CODE ###

L = list(map(int, input().split()))
if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
    print(0)
    exit()

if (L[0]//2)%2 == 1 and (L[1]//2)%2 == 1 and (L[2]//2)%2 == 1:
    print(-1)
    exit()

i = 0
while True:
    i += 1
    L = [L[1]//2+L[2]//2, L[0]//2+L[2]//2, L[0]//2+L[1]//2]
    if L[0]%2 == 1 or L[1]%2 == 1 or L[2]%2 == 1:
        print(i)
        exit()
    if i >= 10**6:
        print(-1)
        exit()
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
import bisect

N = INT()
A = LIST()
B = LIST()
C = LIST()

A.sort()
B.sort()
C.sort()

ans = 0
# for ai in A:
#     i = bisect.bisect_right(B, ai)
#     for bi in B[i:]:
#         j = bisect.bisect_right(C, bi)
#         ans += len(C[j:])

for bi in B:
    i = bisect.bisect_left(A, bi)
    j = bisect.bisect_right(C, bi)
    ans += len(A[:i]) * len(C[j:])


print(ans)

### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
# import bisect

N = INT()
A = LIST()
B = LIST()
C = LIST()

A.sort()
B.sort()
C.sort()

def binsearch(lst, th, ud="up"):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (left + right) // 2
        if ud == "up":
            if lst[mid] > th:
                right = mid
            else:
                left = mid
        else:
            if lst[mid] >= th:
                right = mid
            else:
                left = mid
        
    return right if ud == "up" else left


ans = 0
# for ai in A:
#     i = bisect.bisect_right(B, ai)
#     for bi in B[i:]:
#         j = bisect.bisect_right(C, bi)
#         ans += len(C[j:])

for bi in B:
    i = binsearch(A, bi, "down")
    j = binsearch(C, bi, "up")
    ans += (i+1) * (N-j)


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

import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, k = M()
A = LI()
ans = []
for i in range(n-1, k-1, -1):
    if A[i] > A[i-k]:
        ans.insert(0, 'Yes')
    else:
        ans.insert(0, 'No')
for s in ans:
    print(s)

### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,string
import sys
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, k = M()
A = deque(LI())
ans = deque()
for i in range(k, n):
    if A[i] > A[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import heapq
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
# print(A)
dis=[[-1]*w for i in range(h)]
hq=[]
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            hq.append((0,i,j))
            dis[i][j]=0
dii=[(1,0),(-1,0),(0,1),(0,-1)]
heapq.heapify(hq)
while hq:
    count,i,j=heapq.heappop(hq)
    for di,dj in dii:
        if not (0<=i+di<h and 0<=j+dj<w):
            continue
        if dis[i+di][j+dj]==-1:
            heapq.heappush(hq, (count+1, i+di, j+dj))
            dis[i+di][j+dj]=count+1
            # print(count+1)
ans=0
for Ai in dis:
    ans=max(ans,max(Ai))
print(ans)
# for d in dis:
#     print(d)

    
    


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import heapq
from collections import deque
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
# A=(tuple(input()) for i in range(h))
# print(A)
dis=[[-1]*w for i in range(h)]
hq=deque()
for i in range(h):
    for j in range(w):
        if A[i][j]=="#":
            hq.append((0,i,j))
            dis[i][j]=0
dii=[(1,0),(-1,0),(0,1),(0,-1)]
# heapq.heapify(hq)
ans=0
while hq:
    count,i,j=hq.popleft()
    for di,dj in dii:
        if not (0<=i+di<h and 0<=j+dj<w):
            continue
        if dis[i+di][j+dj]==-1:
            hq.append((count+1, i+di, j+dj))
            dis[i+di][j+dj]=count+1
            ans=max(ans,count+1)
#             # print(count+1)
# ans=0
# for Ai in dis:
#     ans=max(ans,max(Ai))
print(ans)
# for d in dis:
#     print(d)
### BUGGY CODE ###

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

array = []
index = 0

for i in range(len(P)-K+1):
    if sum(P[i:i+K]) >= index:
        index = sum(P[i:i+K])
        array = P[i:i+K]


ans = 0
for i in range(K):
    s = 0
    for j in range(1, array[i]+1):
        s += j
    ans += s / array[i]

print(ans)




### FIXED CODE ###

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


kitaiti = {}

k = 1.0
for i in range(1, 1001):
    kitaiti[i] = k
    k += 0.5

index = 0

for i in range(K):
    index += kitaiti[P[i]]

s = index
ans = index

for i in range(1, len(P)-K+1):
    s = index - kitaiti[P[i-1]] + kitaiti[P[i+K-1]]
    if s > ans: ans = s
    index = s
print(ans)
### BUGGY CODE ###

def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      end1 = len(s1)
      end2 = len(s2)
      checked = [[0 for i in range(len(s2) + 1)] for j in range(len(s1) + 1)]
      dic = {}

      def check(i, j):
        count = 0
        while not checked[i][j] and i < end1 and j < end2 and s1[i] == s2[j]:
          checked[i][j] = 1
          i += 1
          j += 1
          count += 1
        return count

      
      for i in range(end2):
        alp = s2[i]
        if alp in dic:
          dic[alp].append(i)
        else:
          dic[alp] = [i]

      ans = 0

      for i in range(end1):
        alp = s1[i]
        if alp in dic:
          lst = dic[alp]
          for j in lst:
            if not ((i, j) in checked):
              a = check(i, j)
              if a > ans:
                ans = a

      print(ans)
    except EOFError:
      break
solve()


### FIXED CODE ###

while True:
    try:
        s1 = input()
    except EOFError:
        break
    s2 = input()
    BASE = 27
    MOD = 1000000007


    def rolling_hash(s):
        h_lst = [0]
        for c in s:
            h_lst.append((h_lst[-1] * BASE + ord(c)) % MOD)
        return h_lst


    h_lst1 = rolling_hash(s1)
    h_lst2 = rolling_hash(s2)
    length1 = len(s1)
    length2 = len(s2)

    pow_mem = [pow(BASE, i, MOD) for i in range(min(length1, length2) + 1)]


    def check(center):
        hash_set = {(h_lst1[i + center] - h_lst1[i] * pow_mem[center]) % MOD for i in range(length1 - center + 1)}
        for i in range(length2 - center + 1):
            h2 = (h_lst2[i + center] - h_lst2[i] * pow_mem[center]) % MOD
            if h2 in hash_set:return True
        return False


    left = 0
    right = min(length1, length2)
    while right > left + 1:
        center = (left + right) // 2
        if check(center):
            left = center
        else:
            right = center
    print(right if check(right) else left)
### BUGGY CODE ###

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

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


dots = XY[:]

import sys
INT_MAX = sys.maxsize


def sub_f(x, ans_list):
    right_x, left_x = x[0], x[1]
    ans = INT_MAX
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1

        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            ans = min(ans, area)
    #return ans
    ans_list.append(ans)

import itertools
multiprocessing_inputs = []
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    
    multiprocessing_inputs.append((right_x, left_x))
    #ans_list.append(sub_f(right_x, left_x))


import threading
ans_list = []
threadlist = []
for x in multiprocessing_inputs:
    #ans_list = p.map(sub_f, multiprocessing_inputs)
    th = threading.Thread(target=sub_f, args=(x, ans_list))
    threadlist.append(th)
for th in threadlist:
    th.start()
for th in threadlist:
    th.join()

ans = min(ans_list)
print(ans)

### FIXED CODE ###

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
dots = XY[:]

import sys
INT_MAX = sys.maxsize

ans = INT_MAX

import itertools
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1
                
        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            if ans > area:
                ans = area
            
print(ans)
### BUGGY CODE ###

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,x,y=n1()

a=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i<=x and j<=x:
            a.append([(i,j),j-i])
        elif i<=x and x<j<y:
            a.append([(i,j),min(j-i,y-j+1+x-i)])
        elif i<=x:
            a.append([(i,j),j-y+1+x-i])
        elif i<=y and j<=y:
            a.append([(i,j),min(j-i,y-j+1+i-x)])
        elif i<=y:
            a.append([(i,j),min(j-i,j-y+1+i-x)])
        else:
            a.append([(i,j),j-i])
for k in range(1,n):
    ans=0
    for h in range(len(a)):
        if a[h][1]==k:
            ans+=1
    print(ans)

### FIXED CODE ###

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,x,y=n1()

a=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i<=x and j<=x:
            a[j-i]+=1
        elif i<=x and x<j<y:
            a[min(j-i,y-j+1+x-i)]+=1
        elif i<=x:
            a[j-y+1+x-i]+=1
        elif i<=y and j<=y:
            a[min(j-i,y-j+1+i-x)]+=1
        elif i<=y:
            a[min(j-i,j-y+1+i-x)]+=1
        else:
            a[j-i]+=1
for k in range(1,n):
    print(a[k])
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
slst=[]
cnt=[]
for i in range(n-1):
  slst.append(s[i:i+2])
for a,b in enumerate(slst):
  if b=='AC':
    cnt.append(a)
l=[]
for i in range(q):
  x,y=map(int,input().split())
  num=0
  for j in cnt:
    if x-1<=j<=y-2:
      num+=1
  print(num)

### FIXED CODE ###

import bisect
n,q=map(int,input().split())
s=input()
slst=[]
cnt=[]
for i in range(n-1):
  slst.append(s[i:i+2])
for a,b in enumerate(slst):
  if b=='AC':
    cnt.append(a)
l=[]
for i in range(q):
  x,y=map(int,input().split())
  M=bisect.bisect_left(cnt,x-1)
  N=bisect.bisect_right(cnt,y-2)
  print(N-M)
### BUGGY CODE ###

from collections import deque
import math


def main():
    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)]

    d = deque()
    d.append([Ch - 1, Cw - 1])

    cost = [[math.inf for _ in range(W)] for _ in range(H)]
    cost[Ch - 1][Cw - 1] = 0

    while d:
        r, c = d.popleft()

        for dr, dc in [[-1, 0], [1, 0], [0, -1], [0, 1]]:  # 上下左右
            nr = r + dr
            nc = c + dc

            if not 0 <= nr < H:
                continue
            if not 0 <= nc < W:
                continue
            if S[nr][nc] == "#":
                continue
            if cost[nr][nc] <= cost[r][c]:
                continue

            cost[nr][nc] = cost[r][c]
            d.appendleft([nr, nc])

        for dr in range(-2, 3, 1):  # ワープ
            for dc in range(-2, 3, 1):
                if dr == 0 and dc == 0:
                    continue

                nr = r + dr
                nc = c + dc

                if not 0 <= nr < H:
                    continue
                if not 0 <= nc < W:
                    continue
                if S[nr][nc] == "#":
                    continue
                if cost[nr][nc] <= cost[r][c] + 1:
                    continue

                cost[nr][nc] = cost[r][c] + 1
                d.append([nr, nc])

    if cost[Dh - 1][Dw - 1] == math.inf:
        ans = -1
    else:
        ans = cost[Dh - 1][Dw - 1]

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [input() for _ in range(H)]

    Q = deque([[Ch - 1, Cw - 1, 0]])  # 座標とワープ回数

    cost = [[-1 for _ in range(W)] for _ in range(H)]  # ワープ回数を記録

    while Q:
        r, c, cnt = Q.popleft()

        if cost[r][c] != -1:  # 訪れたことがある
            continue

        cost[r][c] = cnt

        for dr in range(-2, 3):
            for dc in range(-2, 3):
                nr = r + dr
                nc = c + dc

                if 0 <= nr < H and 0 <= nc < W and S[nr][nc] == ".":
                    if abs(dr) + abs(dc) == 1:  # 上下左右
                        Q.appendleft([nr, nc, cnt])
                    elif abs(dr) + abs(dc) >= 2:  # ワープ
                        Q.append([nr, nc, cnt + 1])

    print(cost[Dh - 1][Dw - 1])


if __name__ == "__main__":
    main()