#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool makeMagicSquare(int n, vector >& square) { if(n < 3) return false; square.assign(n, vector(n)); if(n % 2 == 1){ int y = 0; int x = n / 2; int a = 0; for(int i=0; i q; int a = 0; for(int y=0; y=0; --y){ for(int x=n-1; x>=0; --x){ if(!((y % 4 == x % 4) || (y % 4 == 3 - x % 4))){ square[y][x] = q.front(); q.pop(); } } } } else{ const int add[][4] = {{4, 1, 2, 3}, {1, 4, 3, 2}, {1, 4, 2, 3}}; int m = n / 2; vector > tmp; makeMagicSquare(m, tmp); for(int y=0; y m / 2 + 1) k = 1; else k = 2; for(int i=0; i<4; ++i) square[y*2+i/2][x*2+i%2] = (tmp[y][x] - 1) * 4 + add[k][i]; } } } return true; } int main() { int n, x, y, z; cin >> n >> x >> y >> z; vector > a; makeMagicSquare(n, a); int b = (a[y-1][x-1] - 1) ^ (z - 1); for(int i=0; i