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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.util.LinkedList;
import java.math.*;
import java.lang.*;
import java.util.PriorityQueue;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class Solution implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static long min(long a,long b)
    {
        if(a>b)
        {
            return b;
        }
        return a;
    }
    public static int min(int a,int b)
    {
        if(a>b)
        {
            return b;
        }
        return a;
    }
    public static long max(long a,long b)
    {
        if(a>b)
        {
            return a;
        }
        return b;
    }
    public static int max(int a,int b)
    {
        if(a>b)
        {
            return a;
        }
        return b;
    }
    static class pair
    {
      long x;
      long y;
      pair(long x,long y)
      {
        this.x = x;
        this.y = y;
      }
    }
    public static int gcd(int a,int b)
    {
        if(a==0)
        return b;
        if(b==0)
        return a;
        while((a%=b)!=0&&(b%=a)!=0);
        return a^b;
    }
    public static long mod(long x)
    {
      if(x>0)
      {
        return x;
      }
      return -x;
    }
    static int mod = (int)1e9+7;
    public static long[][] mult(long[][] a,long[][] b)
    {
      int n = a.length;
      int m = b[0].length;
      long[][] res = new long[n][m];
      for(int i=0;i<n;i++)
      {
        for(int j=0;j<m;j++)
        {
          for(int k=0;k<a[0].length;k++)
          {
            res[i][j]  = (res[i][j]+a[i][k]*b[k][j])%mod;
          }
        }
      }
      return res;
    }
    static ArrayList<Integer>[] list;
    static boolean[] visit;
    public static void dfs(ArrayList<pair> dfs,int u,int n){
      visit[u] = true;
      dfs.add(getpair(u,n));
      for(Integer v:list[u])
      {
        if(!visit[v])
        {
          dfs(dfs,v,n);
        }
      }
    }
    public static pair getpair(int i,int n)
    {
      return new pair(i/n,i%n);
    }
    public static int random(int min,int max)
    {
      return min+(int)((max-min)*Math.random());
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Solution(),"Main",1<<26).start();
    }    public void run() {
      InputReader sc  = new InputReader(System.in);
      PrintWriter out = new PrintWriter(System.out);
      int t1 = 1;
      while(t1-->0)
      {
        int n = sc.nextInt();
        int r1 = sc.nextInt();
        int c1 = sc.nextInt();
        int start = n*(r1-1)+c1-1;
        int r2 = sc.nextInt();
        int c2 = sc.nextInt();
        int end = n*(r2-1)+c2-1;
        char[][] mat = new char[n][];
        for(int i=0;i<n;i++)
        {
          String s = sc.readString();
          mat[i] = s.toCharArray();
        }
        list = new ArrayList[n*n];
        for(int i=0;i<n*n;i++)
        {
          list[i] = new ArrayList<>();
        }
        for(int i=0;i<n;i++)
        {
          for(int j=0;j<n;j++)
          {
            if(mat[i][j]=='1')
            {
              continue;
            }
            int val1 = n*i+j;
            if(j+1<n&&mat[i][j+1]=='0'){
              list[val1].add(val1+1);
              list[val1+1].add(val1);
            }
            if(i+1<n&&mat[i+1][j]=='0'){
              list[val1].add(val1+n);
              list[val1+n].add(val1);
            }
          }
        }
        ArrayList<pair> list1 = new ArrayList<>();
        ArrayList<pair> list2 = new ArrayList<>();
        visit = new boolean[n*n];
        dfs(list1,start,n);
        visit = new boolean[n*n];
        dfs(list2,end,n);
        long min = Long.MAX_VALUE;
        for(pair p1:list1){
          for(pair p2:list2){
            min = min(min,(p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
          }
        }
        out.println(min);
      }
      out.close();
  }
}
