#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void construct_network(int n, int m, int K) {
// sub 1 2 3 7
{
vector<int> Q, row(n), col(m), row2(n), col2(m);
for (int i = 0; i < n; i++) {
Q.clear();
for (int j = 0; j < m; j++) Q.push_back(i*m+j);
row[i] = add_or(Q);
row2[i] = add_xor(Q);
row2[i] = add_not(row2[i]);
}
for (int j = 0; j < m; j++) {
Q.clear();
for (int i = 0; i < n; i++) Q.push_back(i*m+j);
col[j] = add_or(Q);
col2[j] = add_xor(Q);
col2[j] = add_not(col2[j]);
}
vector<int> all;
for (int x = 0; x <= K; x++) {
int y = K-x;
Q.clear();
vector<int> allI, allJ;
for (int i1 = x; i1 < n; i1++) {
int i2 = i1-x;
if (i1 == i2) Q = {row[i1], row2[i1]};
else Q = {row[i1], row[i2]};
allI.push_back(add_and(Q));
}
for (int j1 = y; j1 < m; j1++) {
int j2 = j1-y;
if (j1 == j2) Q = {col[j1], col2[j1]};
else Q = {col[j1], col[j2]};
allJ.push_back(add_and(Q));
}
if (allI.empty() || allJ.empty()) continue;
int or1 = add_or(allI);
int or2 = add_or(allJ);
Q = {or1, or2};
all.push_back(add_and(Q));
}
int ans = add_or(all);
}
return;
// sub 1 2 5
{
vector<int> Q, all;
for (int i1 = 0; i1 < n; i1++) for (int j1 = 0; j1 < m; j1++) {
for (int i2 = i1; i2 < n; i2++) for (int j2 = 0; j2 < m; j2++) {
if (i2-i1+abs(j2-j1) != K) continue;
int id1 = i1*m+j1;
int id2 = i2*m+j2;
Q = {id1, id2};
int p = add_and(Q);
all.push_back(p);
}
}
Q.clear();
for (int i : all) Q.push_back(i);
int ans = add_or(Q);
}
}
// 1 2 3 5 6 7
// 10+11+11+12+8+14 = 66