#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
int x1, y1, t1, x2, y2, t2;
cin >> x1 >> y1 >> t1 >> x2 >> y2 >> t2;
const int size = 9;
int field[size][size];
for(int y=0; y<size; ++y) {
for(int x=0; x<size; ++x) {
cin >> field[y][x];
}
}
int q[4] = {0};
if(y1-1>0) {
int nx = x1;
int ny = y1-1;
if(field[ny][nx] == 0) q[0] += 5;
else if(field[ny][nx] == 1) q[0] += 1;
else q[0] += 10;
if(abs(nx-x2)+abs(ny-y2)<=2) q[0] -= 12;
if(y1 > y2) q[0] += 1;
}
if(x1+1<size) {
int nx = x1+1;
int ny = y1;
if(field[ny][nx] == 0) q[1] += 5;
else if(field[ny][nx] == 1) q[1] += 1;
else q[1] += 10;
if(abs(nx-x2)+abs(ny-y2)<=2) q[1] -= 12;
if(x1 < x2) q[1] += 1;
}
if(y1+1<size) {
int nx = x1;
int ny = y1+1;
if(field[ny][nx] == 0) q[2] += 5;
else if(field[ny][nx] == 1) q[2] += 1;
else q[2] += 10;
if(abs(nx-x2)+abs(ny-y2)<=2) q[2] -= 12;
if(y1 < y2) q[2] += 1;
}
if(x1-1>0) {
int nx = x1-1;
int ny = y1;
if(field[ny][nx] == 0) q[3] += 5;
else if(field[ny][nx] == 1) q[3] += 1;
else q[3] += 10;
if(abs(nx-x2)+abs(ny-y2)<=2) q[3] -= 12;
if(x1 > x2) q[3] += 1;
}
std::random_device rnd;
std::mt19937 mt(rnd());
std::uniform_int_distribution<> rand4(0, 4);
q[rand4(mt)] += 2;
if(abs(x1-x2)+abs(y1-y2) <= 2 && t2 == 0) {
cout << 5 << endl;
} else {
int m = max(q[0], max(q[1], max(q[2], q[3])));
if(q[0] == m) cout << 1 << endl;
else if(q[1] == m) cout << 2 << endl;
else if(q[2] == m) cout << 3 << endl;
else cout << 4 << endl;
}
}
Battle History