Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <chrono>
// #pragma GCC optimize("Ofast")
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL << 58);

int main() {
  cin >> H >> W >> M;
  vec hnum(H, 0), wnum(W, 0), h(M), w(M);
  rep(i, M) {
    cin >> h[i] >> w[i];
    --h[i];
    --w[i];
    ++hnum[h[i]];
    ++wnum[w[i]];
  }
  int mh = *max_element(ALL(hnum)), mw = *max_element(ALL(wnum));
  int ans = mh + mw, num = (count(ALL(hnum), mh)) * count(ALL(wnum), mw);
  rep(i, M) {
    if (hnum[h[i]] + wnum[w[i]] == mh + mw)
      --num;
  }
  cout << ans - (num == 0) << endl;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#define out(x) cout << x << '\\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; // 10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  // os << '{';
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve() {
  lli c = 0, h = 0, n = 0, m, w = 0, ans = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> h >> w >> m;
  vlli a(m), b(m), d(m, 0), e(m, 0);
  rep(i, 0, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    ++d[a[i]];
    ++e[b[i]];
  }
  lli x = *max_element(ALL(d));
  lli y = *max_element(ALL(e));

  // cout << "!: " << x << " " << y << endl;
  ans = x + y;
  // cout << "!: " << ans << endl;
  lli num = (count(ALL(d), x)) * (count(ALL(e), y));
  // cout << "!: " << num << endl;
  rep(i, 0, m) {
    if (d[a[i]] + e[b[i]] == x + y)
      --num;
  }
  c = (num == 0LL);
  ans = ans - c;

  cout << ans << endl;
}

//---------------------------------------------------------------------------------------------------
signed main() { solve(); }