#include #include #include #include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} struct UnionFind { private: vector par, siz; public: UnionFind(int n) : par(n, -1), siz(n, 1) {} int find(int x) { if (par[x] == -1) return x; else { par[x] = find(par[x]); return par[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } bool merge(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } }; const int dx[]={1,0},dy[]={0,1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; N=5; vector C(N,vector(N)); for(int i=0;i>C[i][j]; vector>V; for(int i=0;i(N)); for(int i=l;i<=r;i++)flag[V[i].first][V[i].second]=true; for(int i=0;i>((N-2)*i+j)&1){ flag[i+1][j+1]=true; } } UnionFind uf1(N*N),uf2(N*N); for(int i=0;i=N||y<0||y>=N)continue; if(flag[i][j]){ if(flag[x][y]){ uf1.merge(N*i+j,N*x+y); } }else{ if(!flag[x][y]){ uf2.merge(N*i+j,N*x+y); } } } } int c1=0,c2=0,s1=0,s2=0; ll a1=0,a2=0; for(int i=0;i