alexjercan/bugnet huggingface dataset:
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 3e5 + 7;

int r[N], c[N];
map<PII, int> mp;

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int xx = 0, yy = 0;
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    mp[{x, y}] = 1;
    r[x]++, c[y]++;
    xx = max(xx, r[x]);
    yy = max(yy, c[y]);
  }
  vector<int> vx, vy;
  for (int i = 1; i <= n; i++)
    if (r[i] == xx)
      vx.push_back(i);
  for (int i = 1; i <= m; i++)
    if (c[i] == yy)
      vy.push_back(i);
  int flag = 0;
  for (int i = 0; i < vx.size(); i++) {
    for (int j = 0; j < vy.size(); j++) {
      if (!mp[{vx[i], vy[j]}]) {
        flag = 1;
        break;
      }
    }
    if (flag)
      break;
  }
  if (flag)
    printf("%d\\n", xx + yy);
  else
    printf("%d\\n", xx + yy - 1);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const ULL P = 131;
const int N = 3e5 + 7;

int r[N], c[N];
map<PII, int> mp;

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int xx = 0, yy = 0;
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    mp[{x, y}] = 1;
    r[x]++, c[y]++;
    xx = max(xx, r[x]);
    yy = max(yy, c[y]);
  }
  vector<int> vx, vy;
  for (int i = 1; i <= n; i++)
    if (r[i] == xx)
      vx.push_back(i);
  for (int i = 1; i <= m; i++)
    if (c[i] == yy)
      vy.push_back(i);
  int flag = 0;
  for (int i = 0; i < vx.size(); i++) {
    for (int j = 0; j < vy.size(); j++) {
      if (!mp[{vx[i], vy[j]}])
        flag = 1;
    }
  }
  if (flag)
    printf("%d\\n", xx + yy);
  else
    printf("%d\\n", xx + yy - 1);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 100000000007;
#define ff(i, n) for (i = 0; i < n; i++)
ll row[300001];
int main() {
  ll kamal;
  kamal = 1;
  while (kamal--) {
    ll i, j, h, w, m;
    cin >> h >> w >> m;
    vector<set<ll>> adj(w);
    ff(i, m) {
      ll a, b;
      cin >> a >> b;
      row[a - 1]++;
      adj[b - 1].insert(a - 1);
    }
    vector<pair<ll, ll>> vec;
    ff(i, h) vec.pb(mp(row[i], i));
    sort(vec.begin(), vec.end());
    ll ans = 0;
    ff(i, w) {
      ll e = adj[i].size(), add = 0;
      for (j = vec.size() - 1; j >= 0; j--) {
        if (adj[i].find(vec[j].second) != adj[i].end()) {
          add = max(add, vec[j].first - 1);
        } else {
          add = max(add, vec[j].first);
          break;
        }
      }
      ans = max(ans, e + add);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 100000000007;
#define ff(i, n) for (i = 0; i < n; i++)
ll row[300001];
int main() {
  ll kamal;
  kamal = 1;
  while (kamal--) {
    ll i, j, h, w, m;
    cin >> h >> w >> m;
    vector<set<ll>> adj(w);
    ff(i, m) {
      ll a, b;
      cin >> a >> b;
      row[a - 1]++;
      adj[b - 1].insert(a - 1);
    }
    vector<pair<ll, ll>> vec;
    ff(i, h) vec.pb(mp(row[i], i));
    sort(vec.begin(), vec.end());
    ll ans = 0;
    ff(i, m) {
      ll e = adj[i].size(), add = 0;
      for (j = vec.size() - 1; j >= 0; j--) {
        if (adj[i].find(vec[j].second) != adj[i].end()) {
          add = max(add, vec[j].first - 1);
        } else {
          add = max(add, vec[j].first);
          break;
        }
      }
      ans = max(ans, e + add);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> set;
  vector<pair<int, int>> x(w), y(h);
  for (int i = 0; i < w; ++i)
    x[i].second = i;
  for (int i = 0; i < h; ++i)
    y[i].second = i;
  for (int i = 0; i < m; ++i) {
    int xi, yi;
    cin >> yi >> xi;
    xi--;
    yi--;
    x[xi].first++;
    y[yi].first++;
    set.insert({yi, xi});
  }
  sort(x.rbegin(), x.rend());
  sort(y.rbegin(), y.rend());
  int ret = 0;
  for (auto &&curx : x) {
    for (auto &&cury : y) {
      int d = set.count({cury.second, curx.second});
      ret = max(ret, curx.first + cury.first - d);
      if (d == 0)
        break;
    }
  }
  cout << ret << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> set;
  map<int, int> x, y;
  for (int i = 0; i < m; ++i) {
    int xi, yi;
    cin >> yi >> xi;
    xi--;
    yi--;
    x[xi]++;
    y[yi]++;
    set.insert({yi, xi});
  }
  int ret = 0;
  for (auto &&curx : x) {
    for (auto &&cury : y) {
      int d = set.count({cury.first, curx.first});
      ret = max(ret, curx.second + cury.second - d);
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define endl "\\n"
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
class abc {
public:
  int row, col, total;
};
void trozen() {
  int n, m, to;
  cin >> n >> m >> to;
  vector<int> row(n + 1), col(m + 1);
  set<pair<int, int>> s1;
  // rep(i,n+1) rep(j,m+1) arr[i][j]=0;
  int x, y;
  rep(i, to) cin >> x >> y, row[x]++, col[y]++, s1.insert(make_pair(x, y));
  int maxe = INT_MIN, rows, cols;
  for (int i = 1; i <= n; i++)
    if (maxe < row[i])
      maxe = row[i], rows = i;
  int mine = INT_MIN;
  for (int i = 1; i <= m; i++)
    if (mine < col[i])
      mine = col[i], cols = i;
  vector<int> row1, col1;
  for (int i = 1; i <= n; i++)
    if (row[i] == maxe)
      row1.push_back(i);
  for (int j = 1; j <= m; j++)
    if (col[j] == mine)
      col1.push_back(j);
  for (auto i : row1) {
    for (auto j : col1) {
      if (s1.find({i, j}) == s1.end()) {
        cout << (maxe + mine) << endl;
        return;
      }
    }
  }
  cout << (maxe + mine - 1) << endl;
}
int32_t main() {
  op1;
  op2;
  op3;
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  trozen();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define endl "\\n"
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
void trozen() {
  int n, m, to;
  cin >> n >> m >> to;
  vector<int> row(n + 1), col(m + 1);
  unordered_map<pair<int, int>, bool, hash_pair> m1;
  // rep(i,n+1) rep(j,m+1) arr[i][j]=0;
  int x, y;
  rep(i, to) cin >> x >> y, row[x]++, col[y]++, m1[{x, y}] = true;
  int ans = INT_MIN;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans = max(ans, row[i] + col[j] - m1[{i, j}]);
    }
  }
  cout << ans << endl;
}
int32_t main() {
  op1;
  op2;
  op3;
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  trozen();
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int h, w, m, a[300001], b[300001], p1, p2;
typedef pair<int, int> pi;
set<pi> st;

int main() {
  int i, j, x, y;
  cin >> h >> w >> m;
  vector<int> l, r;
  for (i = 1; i <= m; ++i) {
    cin >> x >> y;
    st.insert(make_pair(x, y));
    a[x]++;
    b[y]++;
    if (a[x] > p1) {
      l.clear();
      p1 = a[x];
    }
    if (a[x] == p1)
      l.push_back(x);
    if (b[y] > p2) {
      r.clear();
      p2 = b[y];
    }
    if (b[y] == p2)
      r.push_back(y);
  }
  for (i = 0; i < l.size(); ++i) {
    for (j = 0; j < r.size(); ++j) {
      if (st.find(make_pair(l[i], r[j])) == st.end()) {
        cout << p1 + p2;
        return 0;
      }
    }
  }
  cout << p1 + p2 - 1 << endl;
}

Error: TLE

Fixed submission:

/*
        Name:
        Author: xiaruize
        Date:
*/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i, j, n) for (int i = int(j); i <= int(n); i++)
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())

int cntr[300005];
int cntc[300005];
vector<pair<int, int>> v;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int r, c;
  for (int i = 0; i < m; i++) {
    cin >> r >> c;
    cntr[r]++;
    cntc[c]++;
    v.pb(mk(r, c));
  }
  int maxr = 0, maxc = 0;
  for (int i = 0; i <= 300001; i++) {
    maxr = max(maxr, cntr[i]);
    maxc = max(maxc, cntc[i]);
  }
  vector<int> rr, cc;
  for (int i = 0; i <= 300001; i++) {
    if (cntr[i] == maxr)
      rr.pb(i);
    if (cntc[i] == maxc)
      cc.pb(i);
  }
  int ans = 0;
  for (int i = 0; i < rr.size(); i++) {
    for (int j = 0; j < cc.size(); j++) {
      if (v.end() != find(ALL(v), mk(rr[i], cc[j]))) {
        ans = 1;
      } else {
        ans = 0;
        break;
      }
    }
    if (!ans)
      break;
  }
  cout << maxr + maxc - ans << endl;
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
int n, m, f;
struct What {
  int id, cnt;
};
What h[300005];
What v[300005];
pair<int, int> coord[300005];

long long hs(int x, int y) { return 1LL * x * 300000 + y; }

pair<int, int> dehs(long long h) { return make_pair(h / 300000, h % 300000); }

bool cmp(What a, What b) { return a.cnt > b.cnt; }

bool cmp2(pair<int, int> a, pair<int, int> b) {
  return hs(a.x, a.y) < hs(b.x, b.y);
}

bool sear(int x, int y) {
  long long l = 1, r = f;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (coord[mid] == make_pair(x, y)) {
      return 1;
    } else if (hs(coord[mid].x, coord[mid].y) < hs(x, y)) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return 0;
}

int main() {
  scanf("%d %d %d", &n, &m, &f);
  for (int i = 1; i <= n; i++) {
    h[i].id = i;
  }
  for (int i = 1; i <= m; i++) {
    v[i].id = i;
  }
  for (int i = 1; i <= f; i++) {
    scanf("%d %d", &coord[i].x, &coord[i].y);
    h[coord[i].x].cnt++;
    v[coord[i].y].cnt++;
  }
  sort(h + 1, h + n + 1, cmp);
  sort(v + 1, v + m + 1, cmp);
  sort(coord + 1, coord + f + 1, cmp2);
  int i = 1, j = 1;
  int ans = 0;
  while (h[i].cnt + v[j].cnt == h[1].cnt + v[1].cnt) {
    bool f = 0;
    if (sear(h[i].id, v[j].id)) {
      f = 1;
      ans = max(ans, h[i].cnt + v[j].cnt - 1);
    }
    if (!f) {
      ans = max(ans, h[i].cnt + v[j].cnt);
    }
    if (h[i + 1].cnt + v[j].cnt >= h[i].cnt + v[j + 1].cnt) {
      i++;
    } else {
      j++;
    }
  }
  printf("%d", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
int n, m, x;
struct What {
  int id, cnt;
};
What h[300005];
What v[300005];
pair<int, int> coord[300005];

bool cmp(What a, What b) { return a.cnt > b.cnt; }

int main() {
  scanf("%d %d %d", &n, &m, &x);
  for (int i = 1; i <= n; i++) {
    h[i].id = i;
  }
  for (int i = 1; i <= m; i++) {
    v[i].id = i;
  }
  for (int i = 1; i <= x; i++) {
    scanf("%d %d", &coord[i].x, &coord[i].y);
    h[coord[i].x].cnt++;
    v[coord[i].y].cnt++;
  }
  sort(h + 1, h + n + 1, cmp);
  sort(v + 1, v + m + 1, cmp);
  int i = 1, j = 1;
  int ans = 0;
  while (h[i].cnt + v[j].cnt == h[1].cnt + v[1].cnt) {
    bool f = 0;
    for (int k = 1; k <= x; k++) {
      if (coord[k].x == h[i].id && coord[k].y == v[j].id) {
        ans = max(ans, h[i].cnt + v[j].cnt - 1);
        f = 1;
        break;
      }
    }
    if (!f) {
      ans = max(ans, h[i].cnt + v[j].cnt);
    }
    if (h[i + 1].cnt + v[j].cnt >= h[i].cnt + v[j + 1].cnt) {
      i++;
    } else {
      j++;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, W, M;
  ;
  cin >> H >> W >> M;

  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  vector<int> countH(H, 0);
  vector<int> counth(H, 0);
  for (int i = 0; i < M; i++) {
    countH.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < H; i++) {
    counth.at(i) = countH.at(i);
  }

  vector<int> countW(W, 0);
  vector<int> countw(W, 0);
  for (int i = 0; i < M; i++) {
    countW.at(B.at(i) - 1)++;
  }

  for (int i = 0; i < W; i++) {
    countw.at(i) = countW.at(i);
  }

  sort(countH.begin(), countH.end());
  reverse(countH.begin(), countH.end());
  sort(countW.begin(), countW.end());
  reverse(countW.begin(), countW.end());

  int maxH = countH.at(0);
  int maxW = countW.at(0);

  long long count1 = 0;
  ;
  for (int i = 0; i < H; i++) {
    if (counth.at(i) == maxH) {
      count1++;
    }
  }
  long long count2 = 0;
  for (int i = 0; i < W; i++) {
    if (countw.at(i) == maxW) {
      count2++;
    }
  }

  long long judge = 0;

  for (int i = 0; i < M; i++) {
    if (counth.at(A.at(i) - 1) == maxH && countw.at(B.at(i) - 1) == maxW) {
      judge++;
    }
  }

  if (judge < count1 * count2) {
    cout << maxH + maxW << endl;
  } else {
    cout << maxH + maxW - 1 << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int H, W, M;
  ;
  cin >> H >> W >> M;

  vector<vector<int>> data(H, vector<int>(W, 0));
  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    data.at(A.at(i) - 1).at(B.at(i) - 1)++;
  }

  vector<int> countH(H, 0);
  vector<int> counth(H, 0);
  for (int i = 0; i < M; i++) {
    countH.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < H; i++) {
    counth.at(i) = countH.at(i);
  }

  vector<int> countW(W, 0);
  vector<int> countw(W, 0);
  for (int i = 0; i < M; i++) {
    countW.at(B.at(i) - 1)++;
  }

  for (int i = 0; i < W; i++) {
    countw.at(i) = countW.at(i);
  }

  sort(countH.begin(), countH.end());
  reverse(countH.begin(), countH.end());
  sort(countW.begin(), countW.end());
  reverse(countW.begin(), countW.end());

  int maxH = countH.at(0);
  int maxW = countW.at(0);

  vector<int> a(H, 400000);
  int count1 = 0;
  for (int i = 0; i < H; i++) {
    if (counth.at(i) == maxH) {
      a.at(i) = i;
      count1++;
    }
  }
  vector<int> b(W, 400000);
  int count2 = 0;
  for (int i = 0; i < W; i++) {
    if (countw.at(i) == maxW) {
      b.at(i) = i;
      count2++;
    }
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  int judge = 0;

  for (int i = 0; i < count1; i++) {
    for (int j = 0; j < count2; j++) {
      if (data.at(a.at(i)).at(b.at(i)) == 0) {
        cout << maxH + maxW << endl;
        return 0;
      }
    }
  }
  cout << maxH + maxW - 1 << endl;
}
Problem p02580 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  int h, w, m;
  scanf("%d %d %d", &h, &w, &m);
  set<pair<int, int>> st;
  vector<int> y(m), x(m);
  vector<pair<int, int>> cnth(h + 1), cntw(w + 1);
  for (int i = 0; i <= h; i++) {
    cnth[i].second = i;
  }
  for (int i = 0; i <= w; i++) {
    cntw[i].second = i;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &y[i], &x[i]);
    st.insert({y[i], x[i]});
    cnth[y[i]].first++;
    cntw[x[i]].first++;
  }
  sort(cnth.begin(), cnth.end(), greater<pair<int, int>>());
  sort(cntw.begin(), cntw.end(), greater<pair<int, int>>());
  int ans = cnth[0].first + cntw[0].first - 1;
  for (int i = 0; i <= h; i++) {
    if (cnth[0].first != cnth[i].first)
      break;
    for (int j = 0; j <= w; j++) {
      if (cntw[0].first != cntw[j].first)
        break;
      if (st.find({cnth[i].second, cntw[j].second}) == st.end()) {
        printf("%d\\n", ans + 1);
        return 0;
      }
    }
  }
  printf("%d\\n", ans);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  int h, w, m;
  scanf("%d %d %d", &h, &w, &m);
  set<pair<int, int>> st;
  vector<int> y(m), x(m);
  vector<pair<int, int>> cnth(h + 1), cntw(w + 1);
  for (int i = 0; i <= h; i++) {
    cnth[i].second = i;
  }
  for (int i = 0; i <= w; i++) {
    cntw[i].second = i;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &y[i], &x[i]);
    st.insert({y[i], x[i]});
    cnth[y[i]].first++;
    cntw[x[i]].first++;
  }
  sort(cnth.begin(), cnth.end(), greater<pair<int, int>>());
  sort(cntw.begin(), cntw.end(), greater<pair<int, int>>());
  int ans = 0;
  for (int i = 0; i <= h; i++) {
    if (cnth[0].first != cnth[i].first)
      break;
    for (int j = 0; j <= w; j++) {
      if (cntw[0].first != cntw[j].first)
        break;
      ans =
          max(ans, cnth[i].first + cntw[j].first -
                       ((st.find({cnth[i].second, cntw[j].second}) != st.end())
                            ? 1
                            : 0));
    }
  }
  printf("%d\\n", ans);
}
Problem p02580 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hsum(w + 1, 0), wsum(h + 1, 0);
  ll hh, ww, hmax = 0, wmax = 0;
  set<pair<ll, ll>> mm;
  set<ll> hs, ws;
  rep(i, m) {
    cin >> hh >> ww;
    mm.emplace(make_pair(hh, ww));
    hsum[ww]++;
    wsum[hh]++;
    if (hsum[ww] > hmax) {
      hmax = hsum[ww];
      hs = {ww};
    }
    if (wsum[hh] > wmax) {
      wmax = wsum[hh];
      ws = {hh};
    }
    if (hsum[ww] == hmax)
      hs.emplace(ww);
    if (wsum[hh] == wmax)
      ws.emplace(hh);
  }
  bool b = 1;
  for (auto i : hs) {
    for (auto j : ws) {
      if (mm.count(make_pair(j, i)) == 0) {
        b = 0;
        break;
      }
    }
    if (b == 0)
      break;
  }
  print(hmax + wmax - b);
  return 0;
}

Error: -11

Fixed submission:

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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  ll h, w, m;
  cin >> h >> w >> m;
  vector<ll> hsum(w, 0), wsum(h, 0);
  ll hh, ww, hmax = 0, wmax = 0, hc = 0, wc = 0;
  vector<vector<bool>> mb(h + 1, vector<bool>(w + 1, 0));
  set<ll> hs, ws;
  rep(i, m) {
    cin >> hh >> ww;
    mb[hh][ww] = 1;
    hsum[ww]++;
    wsum[hh]++;
    if (hsum[ww] > hmax) {
      hmax = hsum[ww];
      hs = {ww};
    }
    if (wsum[hh] > wmax) {
      wmax = wsum[hh];
      ws = {hh};
    }
    if (hsum[ww] == hmax)
      hs.emplace(ww);
    if (wsum[hh] == wmax)
      ws.emplace(hh);
  }
  bool b = 1;
  for (auto i : hs) {
    for (auto j : ws) {
      if (mb[i][j] == 0) {
        b = 0;
        break;
      }
    }
    if (b == 0)
      break;
  }
  print(hmax + wmax - b);
  return 0;
}