#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
void Anna(int N, int K, std::vector<int> R, std::vector<int> C) {
auto serialize = [&](const vector<int> &val) {
int x = 0;
for (const int &i : val) {
x = (x << 1) | i;
}
return x + 1;
};
for (int x = 0; x < N; ++x) {
for (int y = 0; y < N; ++y) {
vector<int> val;
for (int i = 0; i < K; ++i) {
int dx = x - R[i], dy = y - C[i];
if (dx == 0 && dy == 0) {
val.push_back(1);
continue;
}
if (dx == 0) {
if (dy > 0) {
val.push_back(dy % 2);
} else {
val.push_back((-dy + 1) % 2);
}
continue;
}
if (dy == 0) {
if (dx > 0) {
val.push_back((dx + 1) % 2);
} else {
val.push_back((-dx) % 2);
}
continue;
}
if (dx > 0 && dy > 0) {
val.push_back((dx + dy) % 2);
continue;
}
if (dx > 0 && dy < 0) {
val.push_back((-dy) % 2 == 0 && dx % 2 == 0);
continue;
}
if (dy > 0 && dx < 0) {
val.push_back(!(dy % 2 == 0 && (-dx) % 2 == 0));
continue;
}
if (dy < 0 && dx < 0) {
val.push_back((-dx) % 2);
continue;
}
}
SetFlag(x, y, serialize(val));
}
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
vector<int> mp = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
}
vector<int> Bruno(int K, vector<int> value) {
auto unserialize = [&](int x) {
--x;
vector<int> res;
for (int i = 0; i < K; ++i) {
res.push_back(x & 1);
x >>= 1;
}
reverse(res.begin(), res.end());
return res;
};
vector<int> ans;
for (int i = 0; i < K; ++i) {
int val = 0;
vector vals(3, vector<int>(3));
for (int j = 0; j < 9; ++j) {
val = (val << 1) | unserialize(value[j])[i];
}
ans.push_back(mp[val]);
}
return ans;
}