Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif

class UnionFind{
private:
	vi data;
public:
	UnionFind(int size):data(size,-1){}
	bool unite(int x,int y){
		x=root(x);y=root(y);
		if(x!=y){
			if(data[y]<data[x])swap(x,y);
			data[x]+=data[y];data[y]=x;
		}
		return x!=y;
	}
	bool find(int x,int y){
		return root(x)==root(y);
	}
	int root(int x){
		return data[x]<0?x:data[x]=root(data[x]);
	}
	int size(int x){
		return -data[root(x)];
	}
};

vector<vp> uf;

P& operator+=(P&a, const P&b){
    a.F+=b.F;
    a.S+=b.S;
    return a;
}

void unite(int ax,int ay,int bx,int by){
    if(ax==bx && ay==by)return;
    for(auto a:uf){
        for(auto b:a){
            cerr<<b<<'\t';
        }cerr<<endl;
    }cerr<<endl;
    P& A=uf[ay][ax];
    P& B=uf[by][bx];
    if(A.F>=0 && A.S>=0){
        return unite(A.S,A.F,bx,by);
    }
    if(B.F>=0 && B.S>=0){
        return unite(ax,ay,B.S,B.F);
    }
    A+=B;
    B={ay,ax};
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int h,w;
    cin>h>w;
    uf = vector<vp>(h,vp(w));

    vector<string> s(h);
    cin>s;
    cerr<<"Yay"<<flush;
    REP(y,h){
        REP(x,w){
            if(s[y][x]=='#')
                uf[y][x]={-1,0};
            else
                uf[y][x]={0,-1};
        }
    }
    cerr<<"Yay"<<flush;
    REP(y,h){
        REP(x,1,w){
            if(s[y][x]!=s[y][x-1]){
                unite(x,y,x-1,y);
            }
        }
    }
    cerr<<"Yay"<<flush;
    REP(y,1,h){
        REP(x,w){
            if(s[y][x]!=s[y-1][x]){
                unite(x,y,x,y-1);
            }
        }
    }
    cerr<<"Yay"<<flush;
    int ans=0;
    REP(y,h){
        REP(x,w){
            auto&& n=uf[y][x];
            if(n.F<0 || n.S<0){
                ans+=n.F*n.S;
            }
        }
    }
    cout<ans<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:100:16: error: no match for 'operator<<' (operand types are 'ostdmy' and '<unresolved overloaded function type>')
  100 |     cerr<<"Yay"<<flush;
      |                ^
a.cc:36:25: note: candidate: 'template<class T> ostdmy& ostdmy::operator<<(const T&)'
   36 | template<class T>ostdmy&operator<<(const T&t){return*this;}
      |                         ^~~~~~~~
a.cc:36:25: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   couldn't deduce template parameter 'T'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
a.cc:27:26: note: candidate: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
   27 | template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
      |                          ^~~~~~~~
a.cc:27:26: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   couldn't deduce template parameter 'T'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
a.cc:29:34: note: candidate: 'template<class T, class U> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
   29 | template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
      |                                  ^~~~~~~~
a.cc:29:34: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   couldn't deduce template parameter 'T'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
a.cc:31:26: note: candidate: 'template<class T> std::ostream& operator<<(std::ostream&, const std::set<T>&)'
   31 | template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
      |                          ^~~~~~~~
a.cc:31:26: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   couldn't deduce template parameter 'T'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:1715:5: note: candidate: 'template<class _Ch_type, class _Ch_traits, class _Bi_iter> std::basic_ostream<_CharT, _Traits>& std::__cxx11::operator<<(std::basic_ostream<_CharT, _Traits>&, const sub_match<_Bi_iter>&)'
 1715 |     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1715:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41:
/usr/include/c++/14/cstddef:125:5: note: candidate: 'template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator<<(byte, _IntegerType)'
  125 |     operator<<(byte __b, _IntegerType __shift) noexcept
      |     ^~~~~~~~
/usr/include/c++/14/cstddef:125:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   couldn't deduce template parameter '_IntegerType'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/string_view:763:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT, _Traits>)'
  763 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:763:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/bits/basic_string.h:4077:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4077 |     operator<<(basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4077:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/bitset:1687:5: note: candidate: 'template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const bitset<_Nb>&)'
 1687 |     operator<<(std::basic_ostream<_CharT, _Traits>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/bitset:1687:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/c++/14/bits/ios_base.h:46,
                 from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/system_error:339:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const error_code&)'
  339 |     operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
      |     ^~~~~~~~
/usr/include/c++/14/system_error:339:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/c++/14/memory:80,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:56:
/usr/include/c++/14/bits/shared_ptr.h:70:5: note: candidate: 'template<class _Ch, class _Tr, class _Tp, __gnu_cxx::_Lock_policy _Lp> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __shared_ptr<_Tp, _Lp>&)'
   70 |     operator<<(std::basic_ostream<_Ch, _Tr>& __os,
      |     ^~~~~~~~
/usr/include/c++/14/bits/shared_ptr.h:70:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:563:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, _CharT)'
  563 |     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:563:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/ostream:573:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char)'
  573 |     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/ostream:579:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char)'
  579 |     operator<<(basic_ostream<char, _Traits>& __out, char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<char, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/ostream:590:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char)'
  590 |     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<char, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/ostream:595:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char)'
  595 |     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<char, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
/usr/include/c++/14/ostream:654:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const _CharT*)'
  654 |     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
      |     ^~~~~~~~
/usr/include/c++/14/ostream:654:5: note:   template argument deduction/substitution failed:
a.cc:100:18: note:   'ostdmy' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  100 |     cerr<<"Yay"<<flush;
      |                  ^~~~~
In file included from /usr/include