Alice lives on a flat planet that can be modeled as a square grid of size n × n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and column c with ordered pair (r, c). Each cell in the grid is either land or water.

<image> An example planet with n = 5. It also appears in the first sample test.

Alice resides in land cell (r_1, c_1). She wishes to travel to land cell (r_2, c_2). At any moment, she may move to one of the cells adjacent to where she is—in one of the four directions (i.e., up, down, left, or right).

Unfortunately, Alice cannot swim, and there is no viable transportation means other than by foot (i.e., she can walk only on land). As a result, Alice's trip may be impossible.

To help Alice, you plan to create at most one tunnel between some two land cells. The tunnel will allow Alice to freely travel between the two endpoints. Indeed, creating a tunnel is a lot of effort: the cost of creating a tunnel between cells (r_s, c_s) and (r_t, c_t) is (r_s-r_t)^2 + (c_s-c_t)^2.

For now, your task is to find the minimum possible cost of creating at most one tunnel so that Alice could travel from (r_1, c_1) to (r_2, c_2). If no tunnel needs to be created, the cost is 0.

Input

The first line contains one integer n (1 ≤ n ≤ 50) — the width of the square grid.

The second line contains two space-separated integers r_1 and c_1 (1 ≤ r_1, c_1 ≤ n) — denoting the cell where Alice resides.

The third line contains two space-separated integers r_2 and c_2 (1 ≤ r_2, c_2 ≤ n) — denoting the cell to which Alice wishes to travel.

Each of the following n lines contains a string of n characters. The j-th character of the i-th such line (1 ≤ i, j ≤ n) is 0 if (i, j) is land or 1 if (i, j) is water.

It is guaranteed that (r_1, c_1) and (r_2, c_2) are land.

Output

Print an integer that is the minimum possible cost of creating at most one tunnel so that Alice could travel from (r_1, c_1) to (r_2, c_2).

Examples

Input


5
1 1
5 5
00001
11111
00111
00110
00110


Output


10


Input


3
1 3
3 1
010
101
010


Output


8

Note

In the first sample, a tunnel between cells (1, 4) and (4, 5) should be created. The cost of doing so is (1-4)^2 + (4-5)^2 = 10, which is optimal. This way, Alice could walk from (1, 1) to (1, 4), use the tunnel from (1, 4) to (4, 5), and lastly walk from (4, 5) to (5, 5).

In the second sample, clearly a tunnel between cells (1, 3) and (3, 1) needs to be created. The cost of doing so is (1-3)^2 + (3-1)^2 = 8.
import java.io.*;
import java.util.*;

public class Main1130C
{
    static char arr[][];
    static ArrayList<Loc1130> stt,ed;
    static Queue<Loc1130> q = new LinkedList<>();
    static boolean[][] isVisited;
    static int[] dn = {0,0,1,-1};
    static int[] dm = {1,-1,0,0};
    static int dist = Integer.MAX_VALUE;
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N =Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        stt = new ArrayList<>();
        ed = new ArrayList<>();
        stt.add(new Loc1130(Integer.parseInt(st.nextToken())-1, Integer.parseInt(st.nextToken())-1));
        st = new StringTokenizer(br.readLine());
        ed.add(new Loc1130(Integer.parseInt(st.nextToken())-1, Integer.parseInt(st.nextToken())-1));
        arr = new char[N][N];
        isVisited = new boolean[N][N];
        for(int i=0;i<N;++i)
        {
            arr[i] = br.readLine().toCharArray();
        }
        q.offer(stt.get(0));
        while(!q.isEmpty())
        {
            Loc1130 cur = q.poll();
            if(cur.n == ed.get(0).n && cur.m == ed.get(0).m)
            {
                System.out.print("0"); return;
            }
            for(int i=0;i<4;++i)
            {
                int nextn = cur.n+dn[i]; int nextm = cur.m+dm[i];
                if(nextn<0||nextn>=N||nextm<0||nextm>=N) continue;
                if(isVisited[nextn][nextm]) continue;
                if(arr[nextn][nextm] == '1') continue;
                isVisited[nextn][nextm] = true;
                stt.add(new Loc1130(nextn,nextm));
                q.offer(new Loc1130(nextn,nextm));
            }
        }
        for(int i=0;i<N;++i)
        {
            Arrays.fill(isVisited[i],false);
        }
        q.offer(ed.get(0));
        while(!q.isEmpty())
        {
            Loc1130 cur = q.poll();
            for(int i=0;i<4;++i)
            {
                int nextn = cur.n+dn[i]; int nextm = cur.m+dm[i];
                if(nextn<0||nextn>=N||nextm<0||nextm>=N) continue;
                if(isVisited[nextn][nextm]) continue;
                if(arr[nextn][nextm] == '1') continue;
                isVisited[nextn][nextm] = true;
                ed.add(new Loc1130(nextn,nextm));
                q.offer(new Loc1130(nextn,nextm));
            }
        }
        for(Loc1130 loc1 : stt)
        {
            for(Loc1130 loc2 : ed)
            {
                dist = Math.min(dist, loc1.d(loc2));
            }
        }
        bw.write(dist+"");
        bw.close();
    }

}
class Loc1130
{
    int n;
    int m;
    Loc1130(int n,int m)
    {
        this.n = n;
        this.m = m;
    }
    public int d(Loc1130 loc)
    {
        return (this.n-loc.n)*(this.n-loc.n)+(this.m-loc.m)*(this.m-loc.m);
    }
}
