#include <iostream>
#include <vector>

using namespace std;

int n, dy, dx;

bool findway(vector<vector<int>> arr, int sy, int sx, int top = 0, int bot = 0, int left = 0, int right = 0)
{
    if (sy == (dy - 1) && sx == (dx - 1)) return true;
    // left
    if (sx >= 1 && arr[sy][sx - 1] == 0 && left == 0) {
        if (findway(arr, sy, sx - 1, 0, 0, 0, 1))
            return true;
    }
    // right
    if (sx < n - 1 && arr[sy][sx + 1] == 0 && right == 0) {
        if (findway(arr, sy, sx + 1, 0, 0, 1, 0))
            return true;
    }
    // top
    if (sy >= 1 && arr[sy - 1][sx] == 0 && top == 0) {
        if (findway(arr, sy - 1, sx, 0, 1, 0, 0))
            return true;
    }
    // bottom
    if (sy < n - 1 && arr[sy + 1][sx] == 0 && bot == 0) {
        if (findway(arr, sy + 1, sx, 1, 0, 0, 0))
            return true;
    }
    return false;
}

int main()
{
    int sy, sx;
    cin >> n >> sy >> sx >> dy >> dx;
    vector<vector<int>> arr(n);
    for (int i = 0; i < n; ++i) {
        arr[i].resize(n);
        for (int j = 0; j < n; ++j)
            cin >> arr[i][j];
    }
    if (!findway(arr, sy - 1, sx - 1))
        cout << "NO";
    else cout << "YES";
    return 0;
}
