alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\\n'

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  int x, y;
  vector<int> vx(n, 0);
  vector<int> vy(m, 0);
  // vector<set<int>> st(n);
  set<pair<int, int>> pii;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    x--;
    y--;
    vx[x]++;
    vy[y]++;
    // st[x].insert(y);
    pii.insert(MP(x, y));
  }

  int mx = INT_MIN, my = INT_MIN;
  vector<int> mmx, mmy;
  for (int i = 0; i < n; i++) {
    mx = max(vx[i], mx);
  }
  for (int i = 0; i < m; i++) {
    my = max(vy[i], my);
  }

  vector<int> X, Y;

  for (int i = 0; i < n; i++) {
    if (vx[i] == mx) {
      X.PB(i);
    }
  }
  for (int i = 0; i < m; i++) {
    if (vy[i] == my) {
      Y.PB(i);
    }
  }

  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (pii.count(MP(X[i], Y[j])) == 0) {
        // cout << vx[i]<<" "<<vy[j]<<endl;
        cout << mx + my << endl;
        return 0;
      }
    }
  }

  cout << mx + my - 1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\\n'

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  int x, y;
  vector<int> vx(n);
  vector<int> vy(m);
  vector<set<int>> st(n);
  set<pair<int, int>> pii;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    x--;
    y--;
    vx[x]++;
    vy[y]++;
    st[x].insert(y);
    pii.insert(MP(x, y));
  }

  int mx = INT_MIN, my = INT_MIN;
  vector<int> mmx, mmy;
  for (int i = 0; i < n; i++) {
    mx = max(vx[i], mx);
  }
  for (int i = 0; i < m; i++) {
    my = max(vy[i], my);
  }

  vector<int> X, Y;
  for (int i = 0; i < n; i++) {
    if (vx[i] == mx) {
      X.PB(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (vy[i] == my) {
      Y.PB(i);
    }
  }

  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (pii.count(MP(X[i], Y[j])) == 0) {
        // cout << vx[i]<<" "<<vy[j]<<endl;
        cout << mx + my << endl;
        return 0;
      }
    }
  }

  cout << mx + my - 1 << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int N = 3e5 + 5;
int h = 0, k = 0, m = 0, x = 0, y = 0, ans = 0;
map<pair<int, int>, int> mpp;
int row[N];
int col[N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> h >> k >> m;
  vector<int> p, q;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    row[x]++;
    col[y]++;
    mpp[{x, y}] = 1;
  }

  x = *max_element(row + 1, row + h + 1);
  y = *max_element(col + 1, col + k + 1);

  for (int i = 1; i <= h; i++) {
    if (row[i] == x)
      p.push_back(i);
  }

  for (int i = 1; i <= k; i++) {
    if (col[i] == y)
      q.push_back(i);
  }

  for (auto i : p) {
    for (auto j : q) {
      if (mpp[{i, j}]) {
        ans = max(ans, x + y - 1);
      } else {
        ans = max(ans, x + y);
        cout << ans;
        return 0;
      }
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

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

const int N = 3e5 + 5;
int h = 0, k = 0, m = 0, x = 0, y = 0, ans = 0;
map<pair<int, int>, int> mpp;
int row[N];
int col[N];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> h >> k >> m;
  vector<int> p, q;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    row[x]++;
    col[y]++;
    mpp[{x, y}] = 1;
  }

  x = *max_element(row + 1, row + h + 1);
  y = *max_element(col + 1, col + k + 1);

  for (int i = 1; i <= h; i++) {
    if (row[i] == x)
      p.push_back(i);
  }

  for (int i = 1; i <= k; i++) {
    if (col[i] == y)
      q.push_back(i);
  }

  for (auto i : p) {
    for (auto j : q) {
      if (mpp[{i, j}]) {
        ans = max(ans, x + y - 1);
      } else
        ans = max(ans, x + y);
    }
  }
  cout << ans;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  int r[H], c[W];
  rep(i, H) r[i] = 0;
  rep(i, W) c[i] = 0;
  map<pair<int, int>, bool> b;

  vector<int> hv, wv;
  rep(i, M) {
    int hh, ww;
    cin >> hh >> ww;
    hh--;
    ww--;
    hv.push_back(hh);
    wv.push_back(ww);
    r[hh]++;
    c[ww]++;
    b[make_pair(hh, ww)] = true;
  }
  set<int> h(hv.begin(), hv.end()), w(wv.begin(), wv.end());

  int max_h = 0, max_w = 0;
  vector<int> hm, wm;
  for (int hh : h) {
    if (r[hh] > max_h) {
      max_h = r[hh];
      hm.clear();
      hm.push_back(hh);
    } else if (r[hh] == max_h)
      hm.push_back(hh);
  }
  for (int ww : w) {
    if (c[ww] > max_w) {
      max_w = c[ww];
      wm.clear();
      wm.push_back(ww);
    } else if (c[ww] == max_w)
      wm.push_back(ww);
  }

  int ans = max_h + max_w;
  bool flag = true;
  for (int hh : hm) {
    for (int ww : wm) {
      if (b[make_pair(hh, ww)] == false) {
        flag = false;
        break;
      }
      if (!flag)
        break;
    }
  }

  if (flag)
    ans--;
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  int r[H], c[W];
  rep(i, H) r[i] = 0;
  rep(i, W) c[i] = 0;
  vector<pair<int, int>> b(M);

  vector<int> hv, wv;
  rep(i, M) {
    int hh, ww;
    cin >> hh >> ww;
    hh--;
    ww--;
    hv.push_back(hh);
    wv.push_back(ww);
    r[hh]++;
    c[ww]++;
    b[i] = make_pair(hh, ww);
  }
  set<int> h(hv.begin(), hv.end()), w(wv.begin(), wv.end());

  int max_h = 0, max_w = 0;
  vector<int> hm, wm;
  for (int hh : h) {
    if (r[hh] > max_h) {
      max_h = r[hh];
      hm.clear();
      hm.push_back(hh);
    } else if (r[hh] == max_h)
      hm.push_back(hh);
  }
  for (int ww : w) {
    if (c[ww] > max_w) {
      max_w = c[ww];
      wm.clear();
      wm.push_back(ww);
    } else if (c[ww] == max_w)
      wm.push_back(ww);
  }

  /*
  if (hm.size()*wm.size()>M) {
          cout << max_h*max_w << endl;
          return 0;
  }
  */
  for (int hh : hm)
    for (int ww : wm) {
      pair<int, int> p = make_pair(hh, ww);
      int exit = 0;
      for (auto bom : b) {
        if (bom == p) {
          exit = 1;
          break;
        }
      }
      if (!exit) {
        cout << max_h + max_w << endl;
        return 0;
      }
    }
  cout << max_h + max_w - 1 << endl;

  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
#define pll pair<ll, ll>
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

map<ll, ll> hb, wb, hb2, wb2;
map<pair<ll, ll>, ll> p;
int main() {
  ll h, w, H, W, M, ans = 0;
  cin >> H >> W >> M;
  rep(i, 0, M) {
    cin >> h >> w;
    hb[h]++;
    wb[w]++;
    p[mp(h, w)]++;
  }
  ll hmax = 0, wmax = 0;
  bool f = false;
  for (auto i : hb)
    hmax = max(hmax, i.second);
  for (auto i : wb)
    wmax = max(wmax, i.second);
  for (auto i : hb) {
    if (i.second == hmax)
      hb2[i.first] = 1;
  }
  for (auto i : wb) {
    if (i.second == wmax)
      wb2[i.first] = 1;
  }
  for (auto i : hb2) {
    if (f)
      break;
    if (i.second == 1) {
      for (auto j : wb2) {
        if (j.second == 1 && p[mp(i.first, j.first)] == 0)
          f = true;
        if (f)
          break;
      }
    }
  }
  if (!f)
    hmax--;
  cout << hmax + wmax;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define pb push_back
#define mp make_pair
#define F .first
#define S .second
#define pll pair<ll, ll>
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll h[330000], w[330000];
map<ll, ll> hb, wb;
map<pair<ll, ll>, ll> p;
int main() {
  ll H, W, M, ans = 0;
  cin >> H >> W >> M;
  rep(i, 0, M) {
    cin >> h[i] >> w[i];
    hb[h[i]]++;
    wb[w[i]]++;
    p[mp(h[i], w[i])]++;
  }
  ll hmax = 0, wmax = 0;
  bool f = false;
  for (auto i : hb)
    hmax = max(hmax, i.second);
  for (auto i : wb)
    wmax = max(wmax, i.second);
  for (auto i : hb) {
    if (f)
      break;
    if (i.second == hmax) {
      for (auto j : wb) {
        if (j.second == wmax && p[mp(i.first, j.first)] == 0)
          f = true;
        if (f)
          break;
      }
    }
  }
  if (!f)
    hmax--;
  cout << hmax + wmax;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf prllf
using namespace std;
#define ll long long
const int N = 2e6 + 9;
map<ll, ll> row, col;
map<pair<ll, ll>, bool> vis;
void slv() {
  ll h, w, m;
  cin >> h >> w >> m;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    row[x]++;
    col[y]++;
    vis[{x, y}] = true;
  }
  vector<pair<ll, ll>> vx, vy;
  ll mxx = 0LL, mxy = 0LL;
  for (ll i = 1; i <= h; i++) {
    if (row[i] > mxx) {
      vx.clear();
      vx.push_back({row[i], i});
      mxx = row[i];
    } else if (row[i] == mxx)
      vx.push_back({mxx, i});
  }
  for (ll i = 1; i <= w; i++) {
    // cout<<i<<" X "<<col[i]<<endl;
    if (col[i] > mxy) {
      vy.clear();
      vy.push_back({col[i], i});
      mxy = col[i];
    } else if (col[i] == mxy)
      vy.push_back({mxy, i});
  }
  // cout<<mxx<<" "<<mxy<<endl;
  ll ans = mxx + mxy - 1;
  for (auto it1 : vx) {
    for (auto it2 : vy) {
      if (!vis[{it1.second, it2.second}]) {
        cout << mxx + mxy << endl;
        return;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ll t;
  t = 1;
  for (int cs = 1; cs <= t; cs++) {
    slv();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf prllf
using namespace std;
#define ll long long
const int N = 2e6 + 9;
map<ll, ll> row, col;
map<pair<ll, ll>, bool> vis;
void slv() {
  ll h, w, m, x, y;
  cin >> h >> w >> m;
  for (ll i = 0; i < m; i++) {
    cin >> x >> y;
    row[x]++;
    col[y]++;
    vis[{x, y}] = true;
  }
  ll ans = 0LL;
  for (auto it1 : row) {
    for (auto it2 : col) {
      if (vis[{it1.first, it2.first}]) {
        ans = max(ans, it1.second + it2.second - 1);
      } else {
        ans = max(ans, it1.second + it2.second);
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ll t;
  t = 1;
  for (int cs = 1; cs <= t; cs++) {
    slv();
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7LL;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> hcnt(H);
  vector<ll> wcnt(W);
  vector<ll> hselect(0);
  vector<ll> wselect(0);
  set<P> s;

  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    hcnt.at(h - 1)++;
    wcnt.at(w - 1)++;
    P p = make_pair(h - 1, w - 1);
    s.insert(p);
  }
  ll maxh = 0;
  ll maxw = 0;
  rep(i, H) {
    if (maxh < hcnt.at(i))
      maxh = hcnt.at(i);
  }
  rep(i, W) {
    if (maxw < wcnt.at(i))
      maxw = wcnt.at(i);
  }
  rep(i, H) {
    if (maxh == hcnt.at(i))
      hselect.push_back(i);
  }
  rep(i, W) {
    if (maxw == wcnt.at(i))
      wselect.push_back(i);
  }
  if (maxh == W || maxw == H) {
    cout << maxh + maxw - 1 << endl;
    return 0;
  }

  bool flag = false;
  rep(i, hselect.size()) {
    rep(j, wselect.size()) {
      P p = make_pair(hselect.at(i), wselect.at(j));
      if (!s.count(p)) {
        flag = true;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag)
    cout << maxh + maxw << endl;
  else
    cout << maxh + maxw - 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7LL;

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> hcnt(H);
  vector<ll> wcnt(W);
  vector<ll> hselect(0);
  vector<ll> wselect(0);
  set<P> s;

  rep(i, M) {
    ll h, w;
    cin >> h >> w;
    hcnt.at(h - 1)++;
    wcnt.at(w - 1)++;
    P p = make_pair(h - 1, w - 1);
    s.insert(p);
  }
  ll maxh = 0;
  ll maxw = 0;
  rep(i, H) {
    if (maxh < hcnt.at(i))
      maxh = hcnt.at(i);
  }
  rep(i, W) {
    if (maxw < wcnt.at(i))
      maxw = wcnt.at(i);
  }
  rep(i, H) {
    if (maxh == hcnt.at(i))
      hselect.push_back(i);
  }
  rep(i, W) {
    if (maxw == wcnt.at(i))
      wselect.push_back(i);
  }

  bool flag = false;
  rep(i, hselect.size()) {
    rep(j, wselect.size()) {
      P p = make_pair(hselect.at(i), wselect.at(j));
      if (!s.count(p))
        flag = true;
    }
  }
  if (flag)
    cout << maxh + maxw << endl;
  else
    cout << maxh + maxw - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  typedef pair<int, int> pair_items;
  set<pair_items> st;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    st.insert({a, b});
  }
  map<int, int> mph, mpw;
  int hmax_value = 0;
  int wmax_value = 0;

  for (auto tmp : st) {
    chmax(hmax_value, ++mph[tmp.first]);
    chmax(wmax_value, ++mpw[tmp.second]);
  }

  vector<int> h_maxes, w_maxes;

  for (auto h_item : mph) {
    if (h_item.second == hmax_value) {
      h_maxes.push_back(h_item.first);
    }
  }

  for (auto w_item : mpw) {
    if (w_item.second == wmax_value) {
      w_maxes.push_back(w_item.first);
    }
  }

  for (auto hval : h_maxes) {
    for (auto wval : w_maxes) {
      if (st.find({hval, wval}) == st.end()) {
        cout << hmax_value + wmax_value << endl;
        return 0;
      }
    }
  }
  cout << hmax_value + wmax_value - 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int main() {
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M);
  vector<int> w(M);
  REP(i, M) cin >> h[i] >> w[i];

  vector<int> count_h(H + 1, 0);
  for (int i = 0; i < M; i++) {
    count_h[h[i]]++;
  }
  int Ra = *max_element(count_h.begin(), count_h.end());

  int j = 0;
  vector<int> h_que(H, -1);
  for (int i = 0; i < H; i++) {
    if (count_h[i] == Ra) {
      h_que[j] = (i);
      j++;
    }
  }

  vector<int> count_w(W + 1, 0);
  for (int i = 0; i < M; i++) {
    count_w[w[i]]++;
  }
  int Wa = *max_element(count_w.begin(), count_w.end());

  j = 0;
  vector<int> w_que(W, -1);
  for (int i = 0; i < W; i++) {
    if (count_w[i] == Wa) {
      w_que[j] = i;
      j++;
    }
  }

  typedef pair<int, int> indexes;
  queue<indexes> que;
  for (int h : h_que) {
    if (h == -1)
      break;
    for (int w : w_que) {
      if (w == -1)
        break;
      que.push(indexes(h, w));
    }
  }

  while (!que.empty()) {
    indexes ij = que.front();
    que.pop();
    bool isFind = false;
    for (int i = 0; i < M; i++) {
      for (int k = 0; k < M; k++) {
        if (ij.first == h[i] && ij.second == w[i]) {
          isFind = true;
          break;
        }
      }
      if (isFind)
        break;
    }

    if (isFind == false) {
      cout << Ra + Wa << endl;
      return 0;
    }
  }

  cout << Ra + Wa - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W, m;
  cin >> H >> W >> m;
  vector<ll> h(m), w(m);
  vector<ll> mhi, mwi;
  REP(i, m) { cin >> h[i] >> w[i], h[i]--, w[i]--; }

  set<pair<ll, ll>> obj;
  REP(i, m) { obj.insert({h[i], w[i]}); }
  ll mh, mw;
  vector<ll> hcnt(H, 0), wcnt(W, 0);
  REP(i, m) { hcnt[h[i]]++, wcnt[w[i]]++; }
  mh = *max_element(ALL(hcnt));
  mw = *max_element(ALL(wcnt));
  DEBUG(mh);
  DEBUG(mw);
  REP(i, H) {
    if (hcnt[i] == mh)
      mhi.push_back(i);
  }
  REP(i, W) {
    if (wcnt[i] == mw)
      mwi.push_back(i);
  }

  for (auto hi : mhi) {
    for (auto wi : mwi) {
      if (!obj.count({hi, wi})) {
        DEBUG(hi);
        DEBUG(wi);
        cout << mh + mw << endl;
        return 0;
      }
    }
  }
  cout << mh + mw - 1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W, m;
  cin >> H >> W >> m;
  vector<ll> h(m), w(m);
  vector<ll> mhi, mwi;
  REP(i, m) { cin >> h[i] >> w[i], h[i]--, w[i]--; }

  set<pair<ll, ll>> obj;
  REP(i, m) { obj.insert({h[i], w[i]}); }
  ll mh, mw;
  vector<ll> hcnt(H, 0), wcnt(W, 0);
  REP(i, m) { hcnt[h[i]]++, wcnt[w[i]]++; }
  mh = *max_element(ALL(hcnt));
  mw = *max_element(ALL(wcnt));
  DEBUG(mh);
  DEBUG(mw);
  REP(i, m) {
    if (hcnt[i] == mh)
      mhi.push_back(i);
    if (wcnt[i] == mw)
      mwi.push_back(i);
  }

  for (auto hi : mhi) {
    for (auto wi : mwi) {
      if (!obj.count({hi, wi})) {
        DEBUG(hi);
        DEBUG(wi);
        cout << mh + mw << endl;
        return 0;
      }
    }
  }
  cout << mh + mw - 1 << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

//---------------------------

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  VL th(h, 0), tw(w, 0);
  VL sh(m), sw(m);

  rep(i, m) {
    cin >> sh[i] >> sw[i];
    sh[i]--;
    sw[i]--;
    th[sh[i]]++;
    tw[sw[i]]++;
  }

  ll hmax = 0, wmax = 0;
  VL Hs, Ws;
  rep(i, h) {
    if (th[i] > hmax) {
      hmax = th[i];
      Hs = {i};
    } else if (th[i] == hmax) {
      Hs.push_back(i);
    } else {
      continue;
    }
  }
  rep(i, w) {
    if (tw[i] > wmax) {
      wmax = tw[i];
      Ws = {i};
    } else if (tw[i] == wmax) {
      Ws.push_back(i);
    } else {
      continue;
    }
  }

  ll ans = hmax + wmax;
  ll poss = (ll)Hs.size() * (ll)Ws.size();
  sort(Hs.begin(), Hs.end());
  sort(Ws.begin(), Ws.end());

  rep(i, m) {
    if (binary_search(Hs.begin(), Hs.end(), sh[i])) {
      if (binary_search(Ws.begin(), Ws.end(), sw[i])) {
        poss--;
      }
    }
  }

  if (poss <= 0)
    ans--;

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

//---------------------------

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  VL th(h, 0), tw(w, 0);

  set<P> S;

  rep(i, m) {
    ll ih, iw;
    cin >> ih >> iw;
    ih--;
    iw--;
    th[ih]++;
    th[iw]++;
    S.insert(P(ih, iw));
  }

  ll hmax = 0, wmax = 0;
  ll h_id, w_id;
  rep(i, h) {
    if (chmax(hmax, th[i]))
      h_id = i;
  }
  rep(i, w) {
    if (chmax(wmax, tw[i]))
      w_id = i;
  }

  ll ans = hmax + wmax;

  P p = P(h_id, w_id);
  if (S.count(p)) {
    ans--;
  }

  cout << ans << endl;

  return 0;
}