#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
inline bool inBoard(int x, int y) {
return (x >= 0 && x < 9 && y >= 0 && y < 9);
}
inline int dist(int a, int b, int c, int d) {
return abs(a-c) + abs(b-d);
}
int t;
int X1, Y1, T1;
int X2, Y2, T2;
int c[9][9];
inline bool hae() {
if (dist(X1, Y1, X2, Y2) > 2) return false;
if (T2 > 3) return false;
return true;
}
int dfs(int px, int py, int dep) {
}
int main() {
cin >> t;
cin >> X1 >> Y1 >> T1;
cin >> X2 >> Y2 >> T2;
rep(i,9) rep(j,9) cin >> c[j][i];
if (hae()) {
cout << 5 << endl;
return 0;
}
int dir = 0;
int val = -1;
rep(i,4) {
if (!inBoard(X1+dx[i], Y1+dy[i])) continue;
int tmp = c[X1+dx[i]][Y1+dy[i]];
if (tmp == 0) {
if (val < 0) {
val = 0;
dir = i+1;
}
} else if (tmp == 2) {
if (val < 1) {
val = 1;
dir = i+1;
}
}
}
cout << dir << endl;
}
Battle History