#include <bits/stdc++.h>
#include "vision.h"
using namespace std;
#define dbg(x) cerr << #x << ' '; print(x); cerr << endl;
void print(int x) {cerr << x;}
void print(long long x) {cerr << x;}
void print(double x) {cerr << x;}
void print(char x) {cerr << x;}
void print(string x) {cerr << x;}
template <class T> void print(vector <T> x);
template <class T> void print(set <T> x);
template <class T> void print(multiset <T> x);
template <class T, class V> void print(pair <T, V> x);
template <class T> void print(vector <T> x) {cerr << "[ "; for(T i : x) {print(i); cerr << ' ';} cerr << ']';}
template <class T> void print(set <T> x) {cerr << "[ "; for(T i : x) {print(i); cerr << ' ';} cerr << ']';}
template <class T> void print(multiset <T> x) {cerr << "[ "; for(T i : x) {print(i); cerr << ' ';} cerr << ']';}
template <class T, class V> void print(pair <T, V> x) {cerr << "{"; print(x.first); cerr << ' '; print(x.second); cerr << "}";}
#define ll long long
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define all(x) (x).begin(), (x).end()
#define PII pair <int, int>
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int h, w, k;
int dist(int a, int b){
int xa = a / w, ya = a % w;
int xb = b / w, yb = b % w;
return abs(xa - xb) + abs(ya - yb);
}
void construct_network(int H, int W, int K){
h = H, w = W, k = K;
vector <int> row, col, xrow, xcol;
for(int i = 0; i < h; i++){
vector <int> v;
for(int j = i * w; j < (i + 1) * w; j++) v.pb(j);
row.pb(add_xor(v));
}
for(int i = 0; i < w; i++){
vector <int> v;
for(int j = i; j <= (h - 1) * w + i; j += w){
v.pb(j);
}
col.pb(add_xor(v));
}
for(int i = 1; i < h - 1; i++){
vector <int> lef, rig;
for(int j = 0; j < i; j++) lef.pb(row[j]);
for(int j = i + 1; j < h; j++) rig.pb(row[j]);
xrow.pb(add_and({add_or(lef), add_or(rig)}));
}
for(int i = 1; i < w - 1; i++){
vector <int> lef, rig;
for(int j = 0; j < i; j++) lef.pb(col[j]);
for(int j = i + 1; j < w; j++) rig.pb(col[j]);
xcol.pb(add_and({add_or(lef), add_or(rig)}));
}
add_or({add_and({add_not(add_or(row)), add_not(add_or(xcol))}), add_and({add_not(add_or(col)), add_not(add_or(xrow))})});
}