Problem p04000 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...) 1
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto v : V)
    os << v << " ";
  return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;
const ll maxn = 5 * 100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main() {

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  IOS ll h, w, n;
  cin >> h >> w >> n;
  map<pll, ll> m;
  for (ll ii = 0; ii < n; ii++) {
    ll a, b;
    cin >> a >> b;
    for (ll i = -2; i <= 0; i++) {
      for (ll j = -2; j <= 0; j++) {
        if (a + i >= 1 && b + j >= 1 && a + i <= h - 2 && b + j <= w - 2)
          m[mp(a + i, b + j)]++;
      }
    }
  }
  ll ans[10] = {0};
  for (auto x : m) {
    // trace(x.ff.ff,x.ff.ss,x.ss);
    ans[x.ss]++;
  }
  ll sum = 0;
  for (ll i = 1; i <= 9; i++)
    sum += ans[i];
  cout << (h - 2) * (w - 2) - sum << endl;
  for (ll i = 1; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...) 1
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
  os << "[ ";
  for (auto v : V)
    os << v << " ";
  return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;
const ll maxn = 5 * 100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main() {

  IOS ll h, w, n;
  cin >> h >> w >> n;
  map<pll, ll> m;
  for (ll ii = 0; ii < n; ii++) {
    ll a, b;
    cin >> a >> b;
    for (ll i = -2; i <= 0; i++) {
      for (ll j = -2; j <= 0; j++) {
        if (a + i >= 1 && b + j >= 1 && a + i <= h - 2 && b + j <= w - 2)
          m[mp(a + i, b + j)]++;
      }
    }
  }
  ll ans[10] = {0};
  for (auto x : m) {
    // trace(x.ff.ff,x.ff.ss,x.ss);
    ans[x.ss]++;
  }
  ll sum = 0;
  for (ll i = 1; i <= 9; i++)
    sum += ans[i];
  cout << (h - 2) * (w - 2) - sum << endl;
  for (ll i = 1; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}