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

R,C,K = map(int,input().split())
board = [[0 for _ in range(C)] for __ in range(R)]
for _ in range(K):
  r,c,v = map(int,input().split())
  board[r-1][c-1] = v

dp = [[[0 for _ in range(C)] for __ in range(R)] for ___ in range(4)]
ans = 0
for i in range(R):
  for j in range(C):
    dp[1][i][j] = max(dp[1][i][j],dp[0][i][j]+board[i][j])
    for k in range(4):
      if j>0:
        dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
      if j>0 and k>0:
        dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+board[i][j])
      if i>0:
        dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
        dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j]+board[i][j])
      ans = max(ans,dp[k][i][j])
#print(*board,sep='\n')
#print(*dp,sep='\n')
print(ans)

### FIXED CODE ###

R,C,K = map(int,input().split())
board = [[0 for _ in range(C)] for __ in range(R)]
for _ in range(K):
  r,c,v = map(int,input().split())
  board[r-1][c-1] = v

dp0 = [[0]*C for _ in range(R)]
dp1 = [[0]*C for _ in range(R)]
dp2 = [[0]*C for _ in range(R)]
dp3 = [[0]*C for _ in range(R)]

ans = 0
for i in range(R):
  for j in range(C):
    if dp1[i][j] < dp0[i][j]+board[i][j]:
      dp1[i][j] = dp0[i][j]+board[i][j]
    if j>0:
      if dp0[i][j] < dp0[i][j-1]:
        dp0[i][j] = dp0[i][j-1]
      if dp1[i][j] < dp1[i][j-1]:
        dp1[i][j] = dp1[i][j-1]
      if dp2[i][j] < dp2[i][j-1]:
        dp2[i][j] = dp2[i][j-1]
      if dp3[i][j] < dp3[i][j-1]:
        dp3[i][j] = dp3[i][j-1]
      if dp1[i][j] < dp0[i][j-1]+board[i][j]:
        dp1[i][j] = dp0[i][j-1]+board[i][j]
      if dp2[i][j] < dp1[i][j-1]+board[i][j]:
        dp2[i][j] = dp1[i][j-1]+board[i][j]
      if dp3[i][j] < dp2[i][j-1]+board[i][j]:
        dp3[i][j] = dp2[i][j-1]+board[i][j]
    if i>0:
      if dp0[i][j] < dp0[i-1][j]:
        dp0[i][j] = dp0[i-1][j]
      if dp0[i][j] < dp1[i-1][j]:
        dp0[i][j] = dp1[i-1][j]
      if dp0[i][j] < dp2[i-1][j]:
        dp0[i][j] = dp2[i-1][j]
      if dp0[i][j] < dp3[i-1][j]:
        dp0[i][j] = dp3[i-1][j]
      if dp1[i][j] < dp0[i-1][j]+board[i][j]:
        dp1[i][j] = dp0[i-1][j]+board[i][j]
      if dp1[i][j] < dp1[i-1][j]+board[i][j]:
        dp1[i][j] = dp1[i-1][j]+board[i][j]
      if dp1[i][j] < dp2[i-1][j]+board[i][j]:
        dp1[i][j] = dp2[i-1][j]+board[i][j]
      if dp1[i][j] < dp3[i-1][j]+board[i][j]:
        dp1[i][j] = dp3[i-1][j]+board[i][j]
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))
### BUGGY CODE ###

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

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(1, N + 1):
        p = (N - i) % 2
        if p == 0:
            for l in range(N + 1 - i):
                r = l + i
                t0 = dp[l + 1][r] + a[l]
                t1 = dp[l][r - 1] + a[r - 1]
                if t0 > t1:
                    dp[l][r] = t0
                else:
                    dp[l][r] = t1
        else:
            for l in range(N + 1 - i):
                r = l + i
                t0 = dp[l + 1][r] - a[l]
                t1 = dp[l][r - 1] - a[r - 1]
                if t0 < t1:
                    dp[l][r] = t0
                else:
                    dp[l][r] = t1
    print(dp[0][N])
main()


### FIXED CODE ###

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

dp = [[0] * (N + 1) for _ in range(N + 1)]
for l in range(1, N + 1):
  for i in range(N + 1 - l):
    j = i + l
    if (N - l) % 2 == 0:
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
print(dp[0][N])
### BUGGY CODE ###

import copy

def continue_cnt(A):
	Datas, Cnts = [A[0]], [1]
	index = 0
	for i in range(1, len(A)):
		if A[i] == Datas[index]:
			Cnts[index] += 1
		else:
			Datas.append(A[i])
			Cnts.append(1)
			index += 1
	return Datas, Cnts

def nums_child(S, Cnts):
    res = [1] * len(S)
    if max(Cnts) % 2 == 0:
        cnts = max(Cnts)
    else:
        cnts = max(Cnts) - 1

    for _ in range(cnts):
        num = copy.deepcopy(res)
        for i in range(len(S)):
            if num[i] > 0:
                res[i] -= num[i]
                if S[i] == "R":
                    res[i + 1] += num[i]
                else:
                    res[i - 1] += num[i]

    return res


S = input()
Datas, Cnts = continue_cnt(S)  # 実は Datas の情報は明らかなので要らない

print(" ".join(map(str, nums_child(S, Cnts))))


### FIXED CODE ###

def runLength(str):
    """文字列strをランレングス圧縮して返す関数
    ex: "0000111101" => [(0,4), (1,4), (0,1), (1,1)]
    """
    res = []
    data, count = str[0], 1
    for i in range(1, len(str)):
        if str[i] == data:
            count += 1
        else:
            res.append((data, count))
            data, count = str[i], 1
    res.append((data, count))
    return res

S = input()  # S[0] == "R", S[-1] == "L"

ans = [0] * len(S)
ind = -1
for rl in runLength(S):
    if rl[0] == "R":
        ind += rl[1]
        ans[ind] += rl[1] - rl[1] // 2
        ans[ind+1] += rl[1] // 2
        #print("now", rl, *ans)
    else:
        ans[ind] += rl[1] // 2
        ans[ind+1] += rl[1] - rl[1] // 2
        ind += rl[1]
        #print("now", rl, *ans)

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

from  collections import deque,Counter
N,M,K=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]

user=[0 for i in range(N+1)]
graph_ab=[[] for i in range(N+1)]
graph_cd=[[] for i in range(N+1)]
visit_list=[[] for i in range(N+1)]

for i in range(M):
    a,b=AB[i]
    graph_ab[a].append(b)
    graph_ab[b].append(a)

for j in range(1,N+1):
    stack=deque([j])
    visited=[None for i in range(N+1)]
    visited[j]='rd'
    while stack:
        x=stack.popleft()
        for i in graph_ab[x]:
            if visited[i] is None:
                visited[i]='rd'
                stack.append(i)
    visit_list[j]=visited
    
for i in range(K):
    c,d=CD[i]
    if visit_list[c][d]=='rd':
        graph_cd[c].append(d)
        graph_cd[d].append(c)

for i in range(1,N+1):
    user[i]=Counter(visit_list[i])['rd']-len(graph_ab[i])-len(graph_cd[i])-1

del user[0]
print(*user)

### FIXED CODE ###

from  collections import deque,Counter
N,M,K=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
CD=[list(map(int,input().split())) for i in range(K)]

user=[0 for i in range(N+1)]
graph_ab=[[] for i in range(N+1)]
graph_cd=[[] for i in range(N+1)]
visited=[0 for i in range(N+1)]
for i in range(M):
    a,b=AB[i]
    graph_ab[a].append(b)
    graph_ab[b].append(a)
time=0
for j in range(1,N+1):
    if visited[j]==0:
        stack=deque([j])
        time+=1
        visited[j]=time
        while stack:
            x=stack.popleft()
            for i in graph_ab[x]:
                if visited[i]==0:
                    visited[i]=time
                    stack.append(i)
#     visit_list[j]=visited
counter=Counter(visited) 
for i in range(K):
    c,d=CD[i]
    if visited[c]==visited[d]:
        graph_cd[c].append(d)
        graph_cd[d].append(c)

for i in range(1,N+1):
    user[i]=counter[visited[i]]-len(graph_ab[i])-len(graph_cd[i])-1

del user[0]
print(*user)
### BUGGY CODE ###

from collections import Counter

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

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)

### FIXED CODE ###

from collections import Counter

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

c=Counter(S+'RGB')
ans = (c['R']-1)*(c['G']-1)*(c['B']-1)

max_d = (N-3)//2+1

for d in range(1,max_d+1):
  for i in range(N-2):
    j = i+d
    k = j+d
    if k > N-1:break
    if len(set([S[i],S[j],S[k]]))==3:
      ans -= 1
      
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

### FIXED CODE ###

N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
### BUGGY CODE ###

import math
import sys
n=int(input())
s=input().split()
if '0' in s:
  print(0)
  sys.exit()
l=map(int,s)
ans=math.prod(l)
if ans>10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

import sys
n=int(input())
s=input().split()
if '0' in s:
  print(0)
  sys.exit()
l=list(map(int,s))
max=10**18
ans=1
while n>0:
  ans *= l[n-1]
  n-=1
  if ans>max:
    print(-1)
    sys.exit()
print(ans)
### BUGGY CODE ###

h, w = [int(i) for i in input().split()]
a = []
b = []
for i in range(h):
    a.append(list(input()))
    for j in range(w):
        if a[i][j] == "#":
            b.append([i, j])

for cnt in range(h+w):
    c = []
    for i in range(len(b)):
        y = b[i][0]
        x = b[i][1]
        if y > 0:
            if a[y-1][x] != "#":
                a[y-1][x] = "#"
                c.append([y-1, x])
        if y < h-1:
            if a[y+1][x] != "#":
                a[y+1][x] = "#"
                c.append([y+1, x])
        if x > 0:
            if a[y][x-1] != "#":
                a[y][x-1] = "#"
                c.append([y, x-1])
        if x < w-1:
            if a[y][x+1] != "#":
                a[y][x+1] = "#"
                c.append([y, x+1])
    if len(c) == 0:
        print(cnt)
        break
    b = c

### FIXED CODE ###

from collections import deque
import sys


H, W = [int(_) for _ in input().split()]

M = []
q = deque([])
for i in range(H):
    A = input()
    M.append(list(A))
    for j in range(W):
        if A[j] == '#':
            q.append([j, i, 0])

depth_now = 0
depth = 0
count = 0
while len(q) > 0:
    p = q.popleft()
    x = p[0]
    y = p[1]
    depth = p[2]
    if x - 1 >= 0 and M[y][x-1] == '.':
        q.append([x-1, y, depth+1])
        M[y][x-1] = '#'
    if x + 1 < W and M[y][x+1] == '.':
        q.append([x+1, y, depth+1])
        M[y][x+1] = '#'
    if y - 1 >= 0 and M[y-1][x] == '.':
        q.append([x, y-1, depth+1])
        M[y-1][x] = '#'
    if y + 1 < H and M[y+1][x] == '.':
        q.append([x, y+1, depth+1])
        M[y+1][x] = '#'
print(depth)
### BUGGY CODE ###

count = 10**100


S = input()
n = [1]*len(S)


for j in range(count):
    for i in range(len(S)):
        if S[i] == "R":
            if n[i] >0:
                
                n[i+1] += 1
                n[i] -=1
        if S[i] == "L":
            if n[i] >0:
                n[i-1] += 1
                n[i] -=1
print(n)

### FIXED CODE ###

s=input()
s="L"+s+"R"
N=len(s)
a=[1]*N
for i in range(1,N-1):
    if s[i]=="R" and s[i+1]=="R":
        a[i+2]+=a[i]
        a[i]=0
for i in range(N-1,1,-1):
    if s[i]=="L" and s[i-1]=="L":
        a[i-2]+=a[i]
        a[i]=0
print(*a[1:-1])
### BUGGY CODE ###

# -*- using utf8 -*-
import sys
inputlinevec = sys.stdin.readline().strip().split(' ')
n = int(inputlinevec[0])
x = int(inputlinevec[1])
m = int(inputlinevec[2])

sum_res = x
crcle_list = list()
crcle_idx = 0
pre_a = x

for idx in range(1, n):
    #a范围在0-m之间，不会无限递增，因此很大概率会重复
    #a * a % m这种单变量的式子，一旦a出现了之前出现过的值
    #后续就会出现重复的序列，然后循环
    this_a = (pre_a * pre_a) % m
    pre_a = this_a
    
    if this_a not in crcle_list:
        crcle_list.append(this_a)
        sum_res = sum_res + this_a
    else:
        crcle_step = len(crcle_list) - crcle_list.index(this_a)
        remain_crcle = int((n - idx) / crcle_step)
        remain_crcle_tail = int((n - idx) % crcle_step)
        
        crcle_sum = 0
        crcle_sum_tail = 0
        for a_item in crcle_list[crcle_list.index(this_a):]:
            crcle_sum = crcle_sum + a_item
            remain_crcle_tail = remain_crcle_tail - 1
            if remain_crcle_tail == 0:
                crcle_sum_tail = crcle_sum
        sum_res = sum_res + (remain_crcle * crcle_sum) + crcle_sum_tail
        break
        
    
print(sum_res)

### FIXED CODE ###

# -*- using utf8 -*-
import sys
inputlinevec = sys.stdin.readline().strip().split(' ')
n = int(inputlinevec[0])
x = int(inputlinevec[1])
m = int(inputlinevec[2])

sum_res = x
crcle_dict = dict()
crcle_list = list()
crcle_idx = 0
pre_a = x

for idx in range(1, n):
    #a范围在0-m之间，不会无限递增，因此很大概率会重复
    #a * a % m这种单变量的式子，一旦a出现了之前出现过的值
    #后续就会出现重复的序列，然后循环
    this_a = (pre_a * pre_a) % m
    pre_a = this_a
    
    if this_a not in crcle_dict:
        crcle_dict[this_a] = 1
        crcle_list.append(this_a)
        sum_res = sum_res + this_a
    else:
        crcle_step = len(crcle_list) - crcle_list.index(this_a)
        remain_crcle = int((n - idx) / crcle_step)
        remain_crcle_tail = int((n - idx) % crcle_step)
        
        crcle_sum = 0
        crcle_sum_tail = 0
        for a_item in crcle_list[crcle_list.index(this_a):]:
            crcle_sum = crcle_sum + a_item
            remain_crcle_tail = remain_crcle_tail - 1
            if remain_crcle_tail == 0:
                crcle_sum_tail = crcle_sum
        sum_res = sum_res + (remain_crcle * crcle_sum) + crcle_sum_tail
        break
    
print(sum_res)
### BUGGY CODE ###

N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]

count=0
judge=0

for i in range(1,N+1):
    judge=0
    for lr in LR:
        if lr[0]<=i<=lr[1]:
            judge+=1
    if judge==M:
        count+=1

print(count)

### FIXED CODE ###

N,M=map(int,input().split())
LR=[list(map(int,input().split())) for _ in range(M)]

l=1
r=N

for i in LR:
    #print(i)
    if i[0]>l:
        l=i[0]
    if i[1]<r:
        r=i[1]

if r>=l:
    print(r-l+1)
else:
    print(0)
### BUGGY CODE ###

N = input()
l = list(map(int,input().split()))
answer =[]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        if l[i] == l[j]:
            answer.append("NO")
            break
        else:
            continue
if len(answer)==0:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

N=input()
l=list(map(int,input().split()))
if len(l)!=len(set(l)):
  print("NO")
else:
  print("YES")
### BUGGY CODE ###

a,b,x=map(int,input().split())
m=a//x
ans=0
while b>=m*x:
    if m*x>=a:
        ans+=1
    m+=1
print(ans)

### FIXED CODE ###

a,b,x=map(int,input().split())
if a%x==0:
    print(b//x-a//x+1)
else:
    print(b//x-a//x)
### BUGGY CODE ###

import sys


def main():
    vertex_num, operation_num = map(int, sys.stdin.buffer.readline().split())
    tree = [[] for _ in range(vertex_num)]
    for _ in range(vertex_num - 1):
        a, b = map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split())
        tree[a].append(b)
        tree[b].append(a)
    answer = [[0, True] for _ in range(vertex_num)]
    answer[0][1] = False
    for _ in range(operation_num):
        p, x = map(int, sys.stdin.buffer.readline().split())
        answer[p - 1][0] += x
    q = [0]
    while not q == []:
        now = q.pop(0)
        for next_vertex in tree[now]:
            if answer[next_vertex][1]:
                answer[next_vertex][1] = False
                answer[next_vertex][0] += answer[now][0]
                q.append(next_vertex)
    print(" ".join(map(lambda x: str(x[0]), answer)))


if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
from collections import deque


def main():
    vertex_num, operation_num = map(int, sys.stdin.buffer.readline().split())
    tree = [[] for _ in range(vertex_num)]
    for _ in range(vertex_num - 1):
        a, b = map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split())
        tree[a].append(b)
        tree[b].append(a)
    answer = [0 for _ in range(vertex_num)]
    checked = [True for _ in range(vertex_num)]
    checked[0] = False
    for _ in range(operation_num):
        p, x = map(int, sys.stdin.buffer.readline().split())
        answer[p - 1] += x
    q = deque([0])
    empty_deque = deque()
    while not q == empty_deque:
        now = q.popleft()
        for next_vertex in tree[now]:
            if checked[next_vertex]:
                checked[next_vertex] = False
                answer[next_vertex] += answer[now]
                q.append(next_vertex)
    print(" ".join(map(str, answer)))


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

n, m = map(int, input().split())
breaks = []
for _ in range(m):
  breaks.append(int(input())-1)
stairs = [0 for _ in range(n)]

if n == 1:
  print(1)
else:
  if 0 not in breaks:
    stairs[0]=1

  if 1 not in breaks:
    stairs[1]=1  

  for i in range(n):
    if i+1 not in breaks:
      if i+1>=n:
        pass
      else:
        stairs[i+1]=stairs[i]+stairs[i+1]
    if i+2 not in breaks:
      if i+2>=n:
        pass
      else:
        stairs[i+2]=stairs[i]+stairs[i+2]
    if i>3:
      if sum(stairs[i-3:]) == 0:
        break

  print(stairs[-1]%1000000007)
  

### FIXED CODE ###

n, m = map(int, input().split())
stairs = [1]*(n+1)
for _ in range(m):
  stairs[int(input())] = -1

flg = False
for i in range(2,n+1):
  if stairs[i]==-1:
    pass
  elif stairs[i-1]==-1 and stairs[i-2]==-1:
    flg=True
    break
  elif stairs[i-1]==-1:
    stairs[i] = stairs[i-2]
  elif stairs[i-2]==-1:
    stairs[i] = stairs[i-1]
  else:
    stairs[i] = stairs[i-1] + stairs[i-2]
if flg:
  print(0)
else:
  print(stairs[-1]%1000000007)
### BUGGY CODE ###

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


def a_to_b(A):
    c = [0] * N
    for i, a in enumerate(A):
        lb = max(0, i - a)
        c[lb] += 1
        ub = i + a + 1
        if ub < N:
            c[ub] -= 1
    tmp = 0
    B = []
    for ci in c:
        tmp += ci
        B.append(tmp)
    return B


ans = A
for _ in range(K):
    ans = a_to_b(ans)

print(*ans)
pass


### FIXED CODE ###

def a_to_b(A):
    c = [0] * N
    for i, a in enumerate(A):
        lb = max(0, i - a)
        c[lb] += 1
        ub = i + a + 1
        if ub < N:
            c[ub] -= 1
    tmp = 0
    B = []
    for ci in c:
        tmp += ci
        B.append(tmp)
    return B


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

ans = A
for _ in range(K):
    ans = a_to_b(ans)
    if sum(ans) == N ** 2:
        break

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

N,K = map(int, input().split())
P = list(map(int,input().split()))
Px  =[0]*N
temp_max = 0
for i in range(N):
    Px[i] = (1+P[i])/2
for j in range(N-K+1):
    temp_num = sum(Px[j:j+K])
    if temp_max <temp_num:
        temp_max=temp_num
print(temp_max)

### FIXED CODE ###

N,K = map(int, input().split())
P = list(map(int,input().split()))
Px  =[]
for i in range(N):
    Px.append((1+P[i])/2)
temp_num = sum(Px[0:K])
temp_max = sum(Px[0:K])
#print(Px)
for j in range(N-K):
    #print(temp_num)
    temp_num = temp_num-Px[j]+Px[j+K]
    if temp_max <temp_num:
        temp_max=temp_num
print(temp_max)
### BUGGY CODE ###

# 未完成
import numpy as np
import sys
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
kouholist = []
ans = N
if N == 1:
    print(1)
    sys.exit()

for i in range(N):
    x[i], y[i] = map(int, input().split())
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for r in range(N):
            for q in range(N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari

print("{}".format(ans))


### FIXED CODE ###

# 未完成

import sys
N = int(input())
x = [0]*N
y = [0]*N
kouholist = []
ans = N
if N == 1:
    print(1)
    sys.exit()

for i in range(N):
    x[i], y[i] = map(int, input().split())
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for r in range(N):
            for q in range(N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari

print("{}".format(ans))
### BUGGY CODE ###

from collections import defaultdict, deque

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1

maze = []
for _ in range(H):
    row = list(input())
    maze.append(row)

def dfs(i, j, cnt):
    mapped[i][j] = cnt

    for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        x = i + dx
        y = j + dy
        if 0 <= x < H and 0 <= y < W and maze[x][y] == "." and mapped[x][y] == -1:
            dfs(x, y, cnt)
        elif 0 <= x < H and 0 <= y < W and maze[x][y] == "#":
            edges[cnt].add((i, j))

cnt = 0
mapped = [[-1] * W for _ in range(H)]
edges = defaultdict(set)
for i in range(H):
    for j in range(W):
        if maze[i][j] == "." and mapped[i][j] == -1:
            dfs(i, j, cnt)
            cnt += 1

# edges からワープで移動できる島を繋いで、グラフを作る
g = defaultdict(set)
for num in edges:
    for i, j in edges[num]:
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                x = i + dx
                y = j + dy
                if 0 <= x < H and 0 <= y < W and mapped[x][y] != -1 and mapped[x][y] != num:
                    g[num].add(mapped[x][y])
                    g[mapped[x][y]].add(num)

# gでのstart, endの最短距離をbfsで求める
start = mapped[ch][cw]
end = mapped[dh][dw]
q = deque([(start, 0),])
seen = set()

isFind = False
while q:
    size = len(q)
    for _ in range(size):
        node, d = q.popleft()
        seen.add(node)
        if node == end:
            print(d)
            isFind = True
            break
        for adj in g[node]:
            if adj not in seen:
                q.append((adj, d+1))
    if isFind:
        break

if not isFind:
    print(-1)



### FIXED CODE ###

from collections import defaultdict, deque

def main():
    H, W = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    maze = [input() for _ in range(H)]

    INF = 10**12
    path = [[INF] * W for _ in range(H)] # 各マスへの移動コスト
    
    # walk:移動A, warp:移動B
    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]

    q = deque()
    path[ch][cw] = 0
    q.append((ch, cw, 0))

    while q:
        x, y, s = q.popleft()
        for dx, dy in walk: #移動A
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == "." and path[nx][ny] > s:
                path[nx][ny] = s
                q.appendleft((nx, ny, s)) # なぜleft?

        for dx, dy in warp: #移動B
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == "." and path[nx][ny] > s + 1:
                path[nx][ny] = s + 1
                q.append((nx, ny, s+1)) # なぜright?

    ans = path[dh][dw] if path[dh][dw] != INF else "-1"
    print(ans)

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

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

attend = [str(a.index(i)+1) for i in sort_a]

ans = " ".join(attend)
print(ans)

### FIXED CODE ###

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

ans = [""]*n

for i in range(n):
    x = a[i]
    b = ans[a[i] - 1]
    c = str(i+1)
    ans[a[i]-1] = str(i+1)

print(" ".join(ans))