Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

#define debug(v) {printf("L%d %s > ",__LINE__,#v);cout<<(v)<<endl;}
#define debugv(v) {printf("L%d %s > ",__LINE__,#v);for(auto e:(v)){cout<<e<<" ";}cout<<endl;}
#define debuga(m,w) {printf("L%d %s > ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;}
#define debugaa(m,h,w) {printf("L%d %s >\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}}
#define ALL(v) (v).begin(),(v).end()
#define repeat(cnt,l) for(remove_const<decltype(l)>::type cnt=0;(cnt)<(l);++(cnt))
#define rrepeat(cnt,l) for(auto cnt=(l)-1;0<=(cnt);--(cnt))
#define iterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);++(cnt))
#define diterate(cnt,b,e) for(auto cnt=(b);(cnt)!=(e);--(cnt))
const ll MD = 1000000007ll; const long double PI = 3.1415926535897932384626433832795L;
template<typename T1, typename T2> inline void assert_equal(T1 expected, T2 actual) { if (!(expected == actual)) { cerr << "assertion fault: expected=" << expected << " actual=" << actual << endl; abort(); } }
template<typename T1, typename T2> inline void assert_less(T1 actual, T2 threshold) { if (!(actual < threshold)) { cerr << "assertion fault: " << actual << " < (const)" << threshold << endl; abort(); } }
template<typename T1, typename T2> inline void assert_eqless(T1 actual, T2 threshold) { if (!(actual <= threshold)) { cerr << "assertion fault: " << actual << " <= (const)" << threshold << endl; abort(); } }
template<typename T1, typename T2> inline ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << '(' << p.first << ':' << p.second << ')'; return o; }
template<typename Vec> inline ostream& _ostream_vecprint(ostream &o, const Vec& p) { o << '['; for (auto& e : p) o << e << ','; o << ']'; return o; }
template<typename T> inline ostream& operator<<(ostream& o, const vector<T>& v) { return _ostream_vecprint(o, v); }
template<typename T, size_t S> inline ostream& operator<<(ostream& o, const array<T, S>& v) { return _ostream_vecprint(o, v); }
template<typename T> inline T& maxset(T& to, const T& val) { return to = max(to, val); }
template<typename T> inline T& minset(T& to, const T& val) { return to = min(to, val); }
void bye(string s, int code = 0) { cout << s << endl; exit(code); }
mt19937_64 randdev(8901016);
template<typename T> inline T rand(T l, T h) { return uniform_int_distribution<T>(l, h)(randdev); }
template<> inline double rand<double>(double l, double h) { return uniform_real_distribution<double>(l, h)(randdev); }
template<> inline float rand<float>(float l, float h) { return uniform_real_distribution<float>(l, h)(randdev); }

#if defined(_WIN32) || defined(_WIN64)
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#elif defined(__GNUC__)
#else
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
namespace {
#define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E)
    class MaiScanner {
    public:
        template<typename T> void input_integer(T& var) {
            var = 0; T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var * sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) { input_integer<int>(var); return *this; }
        inline MaiScanner& operator>>(long long& var) { input_integer<long long>(var); return *this; }
        inline MaiScanner& operator>>(string& var) {
            int cc = getchar_unlocked();
            for (; !isvisiblechar(cc); cc = getchar_unlocked());
            for (; isvisiblechar(cc); cc = getchar_unlocked())
                var.push_back(cc);
            return *this;
        }
        template<typename IT> void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; }
    };
    class MaiPrinter {
    public:
        template<typename T>
        void output_integer(T var) {
            if (var == 0) { putchar_unlocked('0'); return; }
            if (var < 0)
                putchar_unlocked('-'),
                var = -var;
            char stack[32]; int stack_p = 0;
            while (var)
                stack[stack_p++] = '0' + (var % 10),
                var /= 10;
            while (stack_p)
                putchar_unlocked(stack[--stack_p]);
        }
        inline MaiPrinter& operator<<(char c) { putchar_unlocked(c); return *this; }
        inline MaiPrinter& operator<<(int var) { output_integer<int>(var); return *this; }
        inline MaiPrinter& operator<<(long long var) { output_integer<long long>(var); return *this; }
        inline MaiPrinter& operator<<(char* str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; }
        inline MaiPrinter& operator<<(const string& str) {
            const char* p = str.c_str();
            const char* l = p + str.size();
            while (p < l) putchar_unlocked(*p++);
            return *this;
        }
        template<typename IT> void join(IT begin, IT end, char sep = '\n') { for (auto it = begin; it != end; ++it) *this << *it << sep; }
    };
}
MaiScanner scanner;
MaiPrinter printer;


struct P {
    using T = int;
    T y, x;

    P(T _y = 0, T _x = 0) :y(_y), x(_x) {}

    inline bool operator == (P p) const { return y == p.y && x == p.x; }
    inline bool operator < (P p) const { return y == p.y ? x < p.x : y < p.y; }
    inline P operator+(P p) const { return P(y + p.y, x + p.x); }
    inline P operator-(P p) const { return P(y - p.y, x - p.x); }
    inline P operator+=(P p) { y += p.y; x += p.x; return *this; }
    inline P operator-=(P p) { y -= p.y; x -= p.x; return *this; }
};



template<typename T>
// using T = int;
struct F {
    int height, width;
    vector<T> data;

    F(int h = 1, int w = 1) :height(h), width(w), data(h*w) {}

    inline T& operator()(int y, int x) { return data[x + y * width]; }
    inline T& operator()(P p) { return data[p.x + p.y * width]; }
    inline T operator()(int y, int x) const { return data[x + y * width]; }
    inline T operator()(P p) const { return data[p.x + p.y * width]; }

    inline bool safe(int y, int x) const { return 0 <= y && y < height && 0 <= x && x < width; }
    inline bool safe(P p) const { return 0 <= p.y && p.y < height && 0 <= p.x && p.x < width; }

    inline void fill(T e) { std::fill(ALL(data), e); }
    inline void resize(int h, int w) { height = h; width = w; data.resize(h*w); }

    void print(ostream& os, int setw_arg = 4) {
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x)
                os << setw(setw_arg) << operator()(y, x) << ' ';
            os << '\n';
        }
    }
};


int moving[][2] = { {0,1},{1,0},{-1,0},{0,1} };


int solve() {
    int H, W;
    scanner >> H >> W;

    if (H == 0 && W == 0) return 1;

    F<int> field(H, W);
    P start;

    repeat(y, H) {
        string str;
        scanner >> str;
        repeat(x, W) {
            field(y, x) = !(str[x] == '#');
            if (str[x] == '@') start = P(y, x);
        }
    }

    queue<P> q;
    q.push(start);

    ll ans = 1;

    while (!q.empty()) {
        P p = q.front(); q.pop();
        for (auto mv : moving) {
            int vy = mv[0], vx = mv[1];
            if (field.safe(p + P(vy, vx)) && field(p + P(vy, vx))) {
                q.push(p + P(vy, vx));
                ans += 1;
                field(p + P(vy, vx)) = 0;
            }
        }
    }

    printer << ans << endl;
    return 0;
}


int main() {

    while (!solve());

    return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:181:20: error: no match for 'operator<<' (operand types are '{anonymous}::MaiPrinter' and '<unresolved overloaded function type>')
  181 |     printer << ans << endl;
      |     ~~~~~~~~~~~~~~~^~~~~~~
a.cc:81:28: note: candidate: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(char)'
   81 |         inline MaiPrinter& operator<<(char c) { putchar_unlocked(c); return *this; }
      |                            ^~~~~~~~
a.cc:81:44: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'char'
   81 |         inline MaiPrinter& operator<<(char c) { putchar_unlocked(c); return *this; }
      |                                       ~~~~~^
a.cc:82:28: note: candidate: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(int)'
   82 |         inline MaiPrinter& operator<<(int var) { output_integer<int>(var); return *this; }
      |                            ^~~~~~~~
a.cc:82:43: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'int'
   82 |         inline MaiPrinter& operator<<(int var) { output_integer<int>(var); return *this; }
      |                                       ~~~~^~~
a.cc:83:28: note: candidate: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(long long int)'
   83 |         inline MaiPrinter& operator<<(long long var) { output_integer<long long>(var); return *this; }
      |                            ^~~~~~~~
a.cc:83:49: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long int'
   83 |         inline MaiPrinter& operator<<(long long var) { output_integer<long long>(var); return *this; }
      |                                       ~~~~~~~~~~^~~
a.cc:84:28: note: candidate: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(char*)'
   84 |         inline MaiPrinter& operator<<(char* str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; }
      |                            ^~~~~~~~
a.cc:84:45: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'char*'
   84 |         inline MaiPrinter& operator<<(char* str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; }
      |                                       ~~~~~~^~~~~
a.cc:85:28: note: candidate: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(const std::string&)'
   85 |         inline MaiPrinter& operator<<(const string& str) {
      |                            ^~~~~~~~
a.cc:85:53: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
   85 |         inline MaiPrinter& operator<<(const string& str) {
      |                                       ~~~~~~~~~~~~~~^~~
a.cc:21:52: note: candidate: 'template<class T1, class T2> std::ostream& operator<<(std::ostream&, std::pair<_T1, _T2>)'
   21 | template<typename T1, typename T2> inline ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << '(' << p.first << ':' << p.second << ')'; return o; }
      |                                                    ^~~~~~~~
a.cc:21:52: note:   template argument deduction/substitution failed:
a.cc:181:23: note:   couldn't deduce template parameter 'T1'
  181 |     printer << ans << endl;
      |                       ^~~~
a.cc:23:38: note: candidate: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
   23 | template<typename T> inline ostream& operator<<(ostream& o, const vector<T>& v) { return _ostream_vecprint(o, v); }
      |                                      ^~~~~~~~
a.cc:23:38: note:   template argument deduction/substitution failed:
a.cc:181:23: note:   couldn't deduce template parameter 'T'
  181 |     printer << ans << endl;
      |                       ^~~~
a.cc:24:48: note: candidate: 'template<class T, long unsigned int S> std::ostream& operator<<(std::ostream&, const std::array<_Tp, _Nm>&)'
   24 | template<typename T, size_t S> inline ostream& operator<<(ostream& o, const array<T, S>& v) { return _ostream_vecprint(o, v); }
      |                                                ^~~~~~~~
a.cc:24:48: note:   template argument deduction/substitution failed:
a.cc:181:23: note:   couldn't deduce template parameter 'T'
  181 |     printer << ans << endl;
      |                       ^~~~
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:3:
/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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
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:181:23: note:   couldn't deduce template parameter '_IntegerType'
  181 |     printer << ans << endl;
      |                       ^~~~
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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
/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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
/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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans << endl;
      |                       ^~~~
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:181:23: note:   '{anonymous}::MaiPrinter' is not derived from 'std::basic_ostream<_CharT, _Traits>'
  181 |     printer << ans