#include <iostream>
#include <queue>
#include <cmath>
int n;
int k = 0;
std::vector<std::vector<int>> tox(n, std::vector<int>(n));
std::vector<std::vector<bool>> more(n, std::vector<bool>(n));
void prosiri(int x0, int y0) {

}
int put(int i, int j) {
    if (!more[i][j]) k += tox[i][j];
    if (i == n - 1 && j == n - 1)return k;
    long long dole = 1000000000000;
    long long desno = 1000000000000;
    if (j + 1 < n) {
        if(tox)
    }
    return std::min(dole, desno);
}
std::pair<int, int> kopno(std::vector<std::vector<bool>>& more, int x0, int y0) {
    if (x0 + 1 < n && !more[x0 + 1][y0]) return {x0+1, y0};
    if (x0 - 1 >= 0 && !more[x0 - 1][y0]) return { x0 - 1, y0 };
    if (y0 + 1 < n && !more[x0][y0 + 1]) return { x0 , y0 + 1 };
    if (y0 - 1 >= 0 && !more[x0][y0 - 1]) return { x0, y0 - 1 };
    return {-1, -1};
}
int main()
{
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            bool x;
            std::cin >> x;
            more[i][j] = x;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int x;
            std::cin >> x;
            tox[i][j] = x;
        }
    }
}