prithivMLmods/Coder-Stat huggingface dataset:
Problem p02580 (C++)

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

int n, m, k, x, y;
vector<pair<int, int>> p;
vector<int> col, row;

int main() {
  cin >> n >> m >> k;
  row.assign(n + 1, 0);
  col.assign(m + 1, 0);

  int mxr = 0, mxc = 0;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    p.push_back({x, y});
    row[x]++;
    col[y]++;
    mxr = max(row[x], mxr);
    mxc = max(col[x], mxc);
  }

  int qtd = 0, qtdr = 0, qtdc = 0;
  for (int i = 0; i <= n; i++)
    if (row[i] == mxr)
      qtdr++;

  for (int i = 0; i <= m; i++)
    if (col[i] == mxc)
      qtdc++;

  for (auto par : p) {
    if (row[par.first] == mxr && col[par.second] == mxc) {
      qtd++;
    }
  }

  if (qtd == qtdr * qtdc)
    cout << mxr + mxc - 1 << '\n';
  else
    cout << mxr + mxc << '\n';

  return 0;
}


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

int n, m, k, x, y;
vector<pair<int, int>> p;
vector<int> col, row;

int main() {
  cin >> n >> m >> k;
  row.assign(n + 1, 0);
  col.assign(m + 1, 0);

  int mxr = 0, mxc = 0;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    p.push_back({x, y});
    row[x]++;
    col[y]++;
    mxr = max(row[x], mxr);
    mxc = max(col[y], mxc);
  }

  int qtd = 0, qtdr = 0, qtdc = 0;
  for (int i = 0; i <= n; i++)
    if (row[i] == mxr)
      qtdr++;

  for (int i = 0; i <= m; i++)
    if (col[i] == mxc)
      qtdc++;

  for (auto par : p) {
    if (row[par.first] == mxr && col[par.second] == mxc) {
      qtd++;
    }
  }

  if (qtd == qtdr * qtdc)
    cout << mxr + mxc - 1 << '\n';
  else
    cout << mxr + mxc << '\n';

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hp(h), wp(w);
  set<pi> s;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--, x--;
    hp[y]++;
    wp[x]++;
    s.insert(pi(y, x));
  }
  int mh = 0, mw = 0;
  rep(i, h) mh = max(mh, hp[i]);
  rep(i, w) mw = max(mw, wp[i]);

  vector<int> hm, wm;
  rep(i, h) if (hp[i] == mh) hm.push_back(i);
  rep(i, w) if (wp[i] == mw) wm.push_back(i);

  ll ans = mh + mw;

  rep(i, h) rep(j, w) {
    if (s.count(pi(hm[i], wm[j])))
      continue;
    cout << ans << endl;
    return 0;
  }
  cout << --ans << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> hp(h), wp(w);
  set<pi> s;
  rep(i, m) {
    int y, x;
    cin >> y >> x;
    y--, x--;
    hp[y]++;
    wp[x]++;
    s.insert(pi(y, x));
  }
  int mh = 0, mw = 0;
  rep(i, h) mh = max(mh, hp[i]);
  rep(i, w) mw = max(mw, wp[i]);

  vector<int> hm, wm;
  rep(i, h) if (hp[i] == mh) hm.push_back(i);
  rep(i, w) if (wp[i] == mw) wm.push_back(i);

  ll ans = mh + mw;

  for (int y : hm)
    for (int x : wm) {
      if (s.count(pi(y, x)))
        continue;
      cout << ans << endl;
      return 0;
    }
  cout << --ans << endl;

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 300005

int tree[3 * N];
vector<int> G[N];

void update(int node, int b, int e, int idx, int val) {
  if (idx < b || idx > e)
    return;
  if (b == e) {
    tree[node] += val;
    return;
  }
  int mid = (b + e) / 2;
  update(2 * node, b, mid, idx, val);
  update(2 * node + 1, mid + 1, e, idx, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].pb(y);
    update(1, 1, w, y, 1);
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    if (G[i].size()) {
      int cnt = G[i].size();
      for (int v : G[i])
        update(1, 1, w, v, -1);
      cnt += tree[1];
      ans = max(cnt, ans);
      for (int v : G[i])
        update(1, 1, w, v, 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define pi pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 300005

int tree[4 * N];
vector<int> G[N];

void update(int node, int b, int e, int idx, int val) {
  if (idx < b || idx > e)
    return;
  if (b == e) {
    tree[node] += val;
    return;
  }
  int mid = (b + e) / 2;
  update(2 * node, b, mid, idx, val);
  update(2 * node + 1, mid + 1, e, idx, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].pb(y);
    update(1, 1, w, y, 1);
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    if (G[i].size()) {
      int cnt = G[i].size();
      for (int v : G[i])
        update(1, 1, w, v, -1);
      cnt += tree[1];
      ans = max(cnt, ans);
      for (int v : G[i])
        update(1, 1, w, v, 1);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  umap<int, int> row, col;
  umap<pair<int, int>, int, HASH> grid;
  int mx_r = 0, mx_c = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    grid[{x, y}] = 1;
    mx_r = max(mx_r, row[x]);
    mx_c = max(mx_c, col[y]);
  }
  vector<int> a, b;
  for (auto i : row) {
    if (i.second == mx_r)
      a.push_back(i.first);
  }
  for (auto i : col) {
    if (i.second == mx_c)
      b.push_back(i.first);
  }
  int ans = 0;
  int highest = h + w - 1;
  for (int i : a) {
    for (int j : b) {
      ans = max(ans, mx_r + mx_c - grid[{i, j}]);
      if (ans == highest)
        goto end;
    }
  }
end:;
  printf("%d", ans);
}


Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main() {
  int h, w, n;
  scanf("%d%d%d", &h, &w, &n);
  umap<int, int> row, col;
  umap<pair<int, int>, int, HASH> grid;
  int mx_r = 0, mx_c = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    row[x]++;
    col[y]++;
    grid[{x, y}] = 1;
    mx_r = max(mx_r, row[x]);
    mx_c = max(mx_c, col[y]);
  }
  vector<int> a, b;
  for (auto i : row) {
    if (i.second == mx_r)
      a.push_back(i.first);
  }
  for (auto i : col) {
    if (i.second == mx_c)
      b.push_back(i.first);
  }
  int ans = 0;
  int highest = mx_r + mx_c;
  for (int i : a) {
    for (int j : b) {
      ans = max(ans, mx_r + mx_c - grid[{i, j}]);
      if (ans == highest)
        goto end;
    }
  }
end:;
  printf("%d", ans);
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\n"
#define MOD 1000000009

const int MAXN = 2e5 + 15;

using namespace std;

int R[MAXN], C[MAXN];

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  int mrc = 0, mcc = 0, mr, mc;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    R[a]++;
    C[b]++;
    if (C[b] > mcc) {
      mcc = C[b];
      mc = b;
    }
    if (R[a] > mrc) {
      mrc = R[a];
      mr = a;
    }
    mp[{a, b}] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]);
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]);
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout << "here\n"
#define MOD 1000000009

const int MAXN = 3e5 + 15;

using namespace std;

int R[MAXN], C[MAXN];

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  int mrc = 0, mcc = 0, mr, mc;
  map<pair<int, int>, bool> mp;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    R[a]++;
    C[b]++;
    if (C[b] > mcc) {
      mcc = C[b];
      mc = b;
    }
    if (R[a] > mrc) {
      mrc = R[a];
      mr = a;
    }
    mp[{a, b}] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, mcc + R[i + 1] - mp[{i + 1, mc}]);
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, mrc + C[i + 1] - mp[{mr, i + 1}]);
  }
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);

  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

int main(void) {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> mp1, mp2;
  map<P, bool> exist;
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    mp1[hi]++;
    mp2[wi]++;
    exist[P(hi, wi)] = true;
  }
  int colmax = 0, rowmax = 0;
  for (auto [x, y] : mp1) {
    colmax = max(colmax, y);
  }
  for (auto [x, y] : mp2) {
    rowmax = max(rowmax, y);
  }
  set<P> p1, p2;
  for (auto [x, y] : mp1) {
    if (colmax == y) {
      p1.insert(P(x, y));
    }
  }
  for (auto [x, y] : mp2) {
    if (rowmax == y) {
      p2.insert(P(x, y));
    }
  }
  int ans = 0;
  for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) {
    for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) {
      int num = (itr1->second) + (itr2->second);
      int x = itr1->first;
      int y = itr2->first;
      if (exist[P(x, y)])
        num--;
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
// #define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

const int inf = (int)1e9;

int main(void) {
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> mp1, mp2;
  map<P, bool> exist;
  for (int i = 0; i < m; i++) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    mp1[hi]++;
    mp2[wi]++;
    exist[P(hi, wi)] = true;
  }
  int colmax = 0, rowmax = 0;
  for (auto [x, y] : mp1) {
    colmax = max(colmax, y);
  }
  for (auto [x, y] : mp2) {
    rowmax = max(rowmax, y);
  }
  set<P> p1, p2;
  for (auto [x, y] : mp1) {
    if (colmax == y) {
      p1.insert(P(x, y));
    }
  }
  for (auto [x, y] : mp2) {
    if (rowmax == y) {
      p2.insert(P(x, y));
    }
  }
  int ans = 0;
  for (auto itr1 = p1.begin(); itr1 != p1.end(); ++itr1) {
    for (auto itr2 = p2.begin(); itr2 != p2.end(); ++itr2) {
      int num = (itr1->second) + (itr2->second);
      int x = itr1->first;
      int y = itr2->first;
      if (exist[P(x, y)])
        num--;
      else {
        cout << num << endl;
        return 0;
      }
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
// const int MAX = 300001;
const int MAX = 10;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cntx(MAX), cnty(MAX);
  map<pii, int> mp;
  int H, W, N;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    cntx[x]++;
    cnty[y]++;
    mp[pii(x, y)]++;
  }
  int mx = *max_element(cntx.begin(), cntx.end());
  int my = *max_element(cnty.begin(), cnty.end());
  vector<int> X, Y;
  for (int i = 1; i < MAX; i++) {
    if (cntx[i] == mx)
      X.push_back(i);
    if (cnty[i] == my)
      Y.push_back(i);
  }
  for (int x : X) {
    for (int y : Y) {
      if (mp.count(pii(x, y)) == 0) {
        cout << mx + my << '\n';
        return 0;
      }
    }
  }
  cout << mx + my - 1 << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 300001;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  vector<int> cntx(MAX), cnty(MAX);
  map<pii, int> mp;
  int H, W, N;
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    cntx[x]++;
    cnty[y]++;
    mp[pii(x, y)]++;
  }
  int mx = *max_element(cntx.begin(), cntx.end());
  int my = *max_element(cnty.begin(), cnty.end());
  vector<int> X, Y;
  for (int i = 1; i < MAX; i++) {
    if (cntx[i] == mx)
      X.push_back(i);
    if (cnty[i] == my)
      Y.push_back(i);
  }
  for (int x : X) {
    for (int y : Y) {
      if (mp.count(pii(x, y)) == 0) {
        cout << mx + my << '\n';
        return 0;
      }
    }
  }
  cout << mx + my - 1 << '\n';
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define poi 201000
using namespace std;
typedef long long ll;
struct girl {
  int x, y;
  bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; }
} a[poi];
int b[poi], ans, h, w, n, tans;
set<pair<int, int>> s;
inline int re() {
  char x = getchar();
  int k = 1, y = 0;
  while (x < '0' || x > '9') {
    if (x == '-')
      k = -1;
    x = getchar();
  }
  while (x >= '0' && x <= '9') {
    y = (y << 3) + (y << 1) + x - '0';
    x = getchar();
  }
  return y * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
int lookfor(int st) {
  int x = a[st].x;
  for (int i = st;; i++) {
    if (a[i].x != x)
      break;
    s.erase(make_pair(b[a[i].y]--, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
  ans = (*--s.end()).first;
  for (int i = st;; i++) {
    if (a[i].x != x)
      return i;
    ans++;
    s.erase(make_pair(b[a[i].y]++, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
}
signed main() {
  // freopen("lca.in","r",stdin);
  // freopen("lca.out","w",stdout);
  h = re(), w = re(), n = re();
  for (int i = 1; i <= n; i++) {
    a[i].x = re(), a[i].y = re();
    b[a[i].y]++;
  }
  for (int i = 1; i <= w; i++)
    s.insert(make_pair(b[a[i].y], a[i].y));
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n;) {
    i = lookfor(i);
    tans = max(ans, tans);
  }
  wr(tans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define poi 601000
using namespace std;
typedef long long ll;
struct girl {
  int x, y;
  bool operator<(const girl &b) const { return (x ^ b.x) ? x < b.x : y < b.y; }
} a[poi];
int b[poi], ans, h, w, n, tans;
set<pair<int, int>> s;
inline int re() {
  char x = getchar();
  int k = 1, y = 0;
  while (x < '0' || x > '9') {
    if (x == '-')
      k = -1;
    x = getchar();
  }
  while (x >= '0' && x <= '9') {
    y = (y << 3) + (y << 1) + x - '0';
    x = getchar();
  }
  return y * k;
}
void wr(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    wr(x / 10);
  putchar(x % 10 + '0');
}
int lookfor(int st) {
  int x = a[st].x;
  for (int i = st;; i++) {
    if (a[i].x != x)
      break;
    s.erase(make_pair(b[a[i].y]--, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
  ans = (*--s.end()).first;
  for (int i = st;; i++) {
    if (a[i].x != x)
      return i;
    ans++;
    s.erase(make_pair(b[a[i].y]++, a[i].y));
    s.insert(make_pair(b[a[i].y], a[i].y));
  }
}
signed main() {
  // freopen("lca.in","r",stdin);
  // freopen("lca.out","w",stdout);
  h = re(), w = re(), n = re();
  for (int i = 1; i <= n; i++) {
    a[i].x = re(), a[i].y = re();
    b[a[i].y]++;
  }
  for (int i = 1; i <= w; i++)
    s.insert(make_pair(b[a[i].y], a[i].y));
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n;) {
    i = lookfor(i);
    tans = max(ans, tans);
  }
  wr(tans);
  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map<int, bool> mp[N];

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    mp[x[i]][y[i]] = true;
    cnth[x[i]]++, cntw[y[i]]++;
  }
  int mxh = 0, mxw = 0;
  for (int i = 0; i < N; i++) {
    mxh = max(mxh, cnth[i]);
    mxw = max(mxw, cntw[i]);
  }
  vector<int> hall, wall;
  for (int i = 0; i < N; i++) {
    if (cnth[i] == mxh) {
      hall.push_back(i);
    }
    if (cntw[i] == mxw) {
      wall.push_back(i);
    }
  }
  int cnt = 0, mx = 0;
  for (int i = 0; i < hall.size(); i++) {
    for (int j = 0; j < wall.size(); j++) {
      mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
    }
  }
  cout << mx;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map<int, bool> mp[N];

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int h, w, m;
  cin >> h >> w >> m;
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    mp[x[i]][y[i]] = true;
    cnth[x[i]]++, cntw[y[i]]++;
  }
  int mxh = 0, mxw = 0;
  for (int i = 0; i < N; i++) {
    mxh = max(mxh, cnth[i]);
    mxw = max(mxw, cntw[i]);
  }
  vector<int> hall, wall;
  for (int i = 0; i < N; i++) {
    if (cnth[i] == mxh) {
      hall.push_back(i);
    }
    if (cntw[i] == mxw) {
      wall.push_back(i);
    }
  }
  if (hall.size() * wall.size() > m) {
    cout << mxh + mxw << endl;
    return 0;
  }
  int cnt = 0, mx = 0;
  for (int i = 0; i < hall.size(); i++) {
    for (int j = 0; j < wall.size(); j++) {
      mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
    }
  }
  cout << mx;
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll n, m;
map<int, int> x, y;
struct node {
  int x, y;
};
node a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> a[i].x >> a[i].y;
    x[a[i].x]++;
    y[a[i].y]++;
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i <= t; i++)
    maxx = max(maxx, x[a[i].x]), maxy = max(maxy, y[a[i].y]);
  if (x.size() == 1 || y.size() == 1) {
    cout << t << endl;
  } else {
    if (maxx == 1 && maxy == 1) {
      cout << 2 << endl;
    } else {
      ll x1 = 0, x2 = 0, y1 = 0, y2 = 0;
      map<int, int>::iterator it;
      for (it = x.begin(); it != x.end(); it++) {
        if (it->second == maxx)
          x1++;
        else if (it->second == maxx - 1)
          x2++;
      }
      for (it = y.begin(); it != y.end(); it++) {
        if (it->second == maxy)
          y1++;
        else if (it->second == maxy - 1)
          y2++;
      }
      ll ans1 = 0, ans2 = 0;
      ans1 = x1 * y1;
      ans2 = x2 * y1 + x1 * y2;
      for (int i = 1; i <= t; i++) {
        if (maxx + maxy == x[a[i].x] + y[a[i].y]) {
          ans1--;
          ans2++;
        } else if (maxx + maxy - 1 == x[a[i].x] + y[a[i].y]) {
          ans2--;
        }
      }
      if (ans1) {
        cout << maxx + maxy << endl;
      } else {
        cout << maxx + maxy - 1 << endl;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
ll n, m;
map<int, int> x, y;
struct node {
  int x, y;
};
node a[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> a[i].x >> a[i].y;
    x[a[i].x]++;
    y[a[i].y]++;
  }
  int maxx = 0, maxy = 0;
  for (int i = 1; i <= t; i++)
    maxx = max(maxx, x[a[i].x]), maxy = max(maxy, y[a[i].y]);
  if (x.size() == 1 || y.size() == 1) {
    cout << t << endl;
  } else {
    if (maxx == 1 && maxy == 1) {
      cout << 2 << endl;
    } else {
      ll x1 = 0, x2 = 0, y1 = 0, y2 = 0;
      map<int, int>::iterator it;
      for (it = x.begin(); it != x.end(); it++) {
        if (it->second == maxx)
          x1++;
        else if (it->second == maxx - 1)
          x2++;
      }
      for (it = y.begin(); it != y.end(); it++) {
        if (it->second == maxy)
          y1++;
        else if (it->second == maxy - 1)
          y2++;
      }
      ll ans1 = 0, ans2 = 0;
      ans1 = x1 * y1;
      ans2 = x2 * y1 + x1 * y2;
      for (int i = 1; i <= t; i++) {
        if (maxx + maxy == x[a[i].x] + y[a[i].y]) {
          ans1--;
          ans2++;
        } else if (maxx + maxy - 1 == x[a[i].x] + y[a[i].y]) {
          ans2--;
        }
      }
      if (ans1) {
        cout << maxx + maxy << endl;
      } else {
        cout << maxx + maxy - 1 << endl;
      }
    }
  }
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
ll n, m, m1;
ll solve() {
  cin >> n >> m >> m1;
  map<ll, vector<pair<ll, ll>>> mr, mc;
  map<pair<ll, ll>, bool> m2;
  for (ll i = 0; i < m1; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    m2[{x, y}] = true;
    mr[x].push_back({x, y});
    mc[y].push_back({x, y});
  }
  vector<ll> vr, vc;
  ll maxr = 0;
  ll maxc = 0;
  for (auto x : mr) {
    maxr = max(maxr, (ll)x.second.size());
  }
  for (auto x : mc) {
    maxc = max(maxc, (ll)x.second.size());
  }
  for (auto x : mr) {
    if ((ll)x.second.size() == maxr) {
      vr.push_back(x.first);
    }
  }
  for (auto x : mc) {
    if ((ll)x.second.size() == maxc) {
      vc.push_back(x.first);
    }
  }
  bool temp = false;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (m2[{vr[i], vc[j]}] == 0) {
        temp = true;
        break;
      }
    }
  }
  if (temp) {
    cout << maxr + maxc << endl;
  } else {
    cout << maxr + maxc - 1 << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
ll n, m, m1;
void solve() {
  cin >> n >> m >> m1;
  map<ll, vector<pair<ll, ll>>> mr, mc;
  map<pair<ll, ll>, bool> m2;
  for (ll i = 0; i < m1; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    m2[{x, y}] = true;
    mr[x].push_back({x, y});
    mc[y].push_back({x, y});
  }
  vector<ll> vr, vc;
  ll maxr = 0;
  ll maxc = 0;
  for (auto x : mr) {
    maxr = max(maxr, (ll)x.second.size());
  }
  for (auto x : mc) {
    maxc = max(maxc, (ll)x.second.size());
  }
  for (auto x : mr) {
    if ((ll)x.second.size() == maxr) {
      vr.push_back(x.first);
    }
  }
  for (auto x : mc) {
    if ((ll)x.second.size() == maxc) {
      vc.push_back(x.first);
    }
  }
  bool temp = false;
  for (ll i = 0; i < vr.size(); i++) {
    for (ll j = 0; j < vc.size(); j++) {
      if (m2[{vr[i], vc[j]}] == 0) {
        temp = true;
        break;
      }
    }
  }
  if (temp) {
    cout << maxr + maxc << endl;
  } else {
    cout << maxr + maxc - 1 << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const int SIZE = 300000;

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

  int hc[SIZE] = {}, wc[SIZE] = {};
  pii hw[SIZE] = {};
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    hc[h]++;
    wc[w]++;
    hw[i] = {h, w};
  }
  vector<pii> phc, pwc;
  REP(i, SIZE) {
    phc.push_back({hc[i], i});
    pwc.push_back({wc[i], i});
  }
  sort(ALL(phc), greater<pii>());
  sort(ALL(pwc), greater<pii>());

  int hcnt, wcnt;
  vector<int> ht, wt;
  REP(i, SIZE) {
    hcnt = phc[i].first;
    ht.push_back(phc[i].second);
    if (i == SIZE - 1)
      break;
    if (phc[i].first != phc[i + 1].first)
      break;
  }
  REP(i, SIZE) {
    wcnt = pwc[i].first;
    wt.push_back(pwc[i].second);
    if (i == SIZE - 1)
      break;
    if (pwc[i].first != pwc[i + 1].first)
      break;
  }
  sort(ALL(ht));
  sort(ALL(wt));

  int cnt = 0;
  REP(i, M) {
    int h, w;
    h = hw[i].first;
    w = hw[i].second;
    if (find(ALL(ht), h) != ht.end() && find(ALL(wt), w) != wt.end())
      cnt++;
  }
  ll ans = hcnt + wcnt;
  if (cnt == ht.size() * wt.size())
    ans--;
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const int SIZE = 300000;

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

  int hc[SIZE] = {}, wc[SIZE] = {};
  pii hw[SIZE] = {};
  REP(i, M) {
    int h, w;
    cin >> h >> w;
    h--;
    w--;
    hc[h]++;
    wc[w]++;
    hw[i] = {h, w};
  }
  vector<pii> phc, pwc;
  REP(i, SIZE) {
    phc.push_back({hc[i], i});
    pwc.push_back({wc[i], i});
  }
  sort(ALL(phc), greater<pii>());
  sort(ALL(pwc), greater<pii>());

  int hcnt, wcnt;
  vector<int> ht, wt;
  REP(i, SIZE) {
    hcnt = phc[i].first;
    ht.push_back(phc[i].second);
    if (i == SIZE - 1)
      break;
    if (phc[i].first != phc[i + 1].first)
      break;
  }
  REP(i, SIZE) {
    wcnt = pwc[i].first;
    wt.push_back(pwc[i].second);
    if (i == SIZE - 1)
      break;
    if (pwc[i].first != pwc[i + 1].first)
      break;
  }
  sort(ALL(ht));
  sort(ALL(wt));

  int cnt = 0;
  REP(i, M) {
    int h, w;
    h = hw[i].first;
    w = hw[i].second;
    if (binary_search(ALL(ht), h) && binary_search(ALL(wt), w))
      cnt++;
  }
  ll ans = hcnt + wcnt;
  if (cnt == ht.size() * wt.size())
    ans--;
  cout << ans << endl;
}
Problem p02580 (C++)

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

#define froop1(a, n) for (int i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)

#define ll long long

#define pq(name, type) priority_queue<type> name
#define vec(name, type, length, value) vector<type> name(length, value)
#define vec2(name, type, length, width, value)                                 \
  vector<vector<type>> name(length, vector<type>(width, value));

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h;
  vector<ll> w;
  vector<ll> Wid(W, 0);
  vector<ll> Hei(H, 0);
  ll hmax = 0, wmax = 0;
  ll c1 = 0, c2 = 0;
  froop1(0, M) {
    ll a, b;
    cin >> a >> b;
    h.push_back(a);
    w.push_back(b);
    Wid.at(b - 1)++;
    Hei.at(a - 1)++;
    if (hmax < Hei.at(a - 1)) {
      hmax = Hei.at(a - 1);
      c1 = 1;
    } else if (hmax == Hei.at(a - 1)) {
      c1++;
    }
    if (wmax < Wid.at(b - 1)) {
      wmax = Wid.at(b - 1);
      c2 = 1;
    } else if (wmax == Wid.at(b - 1)) {
      c2++;
    }
  }
  ll pat = c1 * c2;
  int sw = 0;
  while (h.size() != 0 && w.size() != 0) {
    ll n = h.at(0) - 1;
    ll m = w.at(0) - 1;
    h.erase(h.begin());
    w.erase(w.begin());
    if (Wid.at(m) == wmax && Hei.at(n) == hmax)
      pat--;
  }
  if (pat == 0) {
    cout << hmax + wmax - 1 << endl;
  } else {
    cout << hmax + wmax << endl;
  }
}


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

#define froop1(a, n) for (int i = a; i < n; i++)
#define froop2(a, n) for (int i = a; i > n; i--)

#define ll long long

#define pq(name, type) priority_queue<type> name
#define vec(name, type, length, value) vector<type> name(length, value)
#define vec2(name, type, length, width, value)                                 \
  vector<vector<type>> name(length, vector<type>(width, value));

int main() {
  ll H, W, M;
  cin >> H >> W >> M;
  vector<ll> h;
  vector<ll> w;
  vector<ll> Wid(W, 0);
  vector<ll> Hei(H, 0);
  ll hmax = 0, wmax = 0;
  ll c1 = 0, c2 = 0;
  froop1(0, M) {
    ll a, b;
    cin >> a >> b;
    h.push_back(a);
    w.push_back(b);
    Wid.at(b - 1)++;
    Hei.at(a - 1)++;
    if (hmax < Hei.at(a - 1)) {
      hmax = Hei.at(a - 1);
      c1 = 1;
    } else if (hmax == Hei.at(a - 1)) {
      c1++;
    }
    if (wmax < Wid.at(b - 1)) {
      wmax = Wid.at(b - 1);
      c2 = 1;
    } else if (wmax == Wid.at(b - 1)) {
      c2++;
    }
  }
  ll pat = c1 * c2;
  int sw = 0;
  for (int i = 0; i < M; i++) {
    ll n = h.at(i) - 1;
    ll m = w.at(i) - 1;
    if (Wid.at(m) == wmax && Hei.at(n) == hmax)
      pat--;
  }
  if (pat == 0) {
    cout << hmax + wmax - 1 << endl;
  } else {
    cout << hmax + wmax << endl;
  }
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  for (int i = 0; i < n; i++) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }
  int mh = 0, mw = 0;
  for (int i = 0; i < h; i++) {
    mh = max(mh, hs[i]);
  }
  for (int i = 0; i < w; i++) {
    mw = max(mw, ws[i]);
  }
  vector<int> is, js;
  for (int i = 0; i < h; i++) {
    if (mh == hs[i]) {
      is.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (mw == ws[i]) {
      js.push_back(i);
    }
  }
  int ans = mh + mw;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s.count(P(is[i], js[j]))) {
        continue;
      }
      cout << ans << endl;
      return 0;
    }
  }
  --ans;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> hs(h), ws(w);
  set<P> s;
  for (int i = 0; i < n; i++) {
    int r, c;
    cin >> r >> c;
    r--;
    c--;
    hs[r]++;
    ws[c]++;
    s.emplace(r, c);
  }
  int mh = 0, mw = 0;
  for (int i = 0; i < h; i++) {
    mh = max(mh, hs[i]);
  }
  for (int i = 0; i < w; i++) {
    mw = max(mw, ws[i]);
  }
  vector<int> is, js;
  for (int i = 0; i < h; i++) {
    if (mh == hs[i]) {
      is.push_back(i);
    }
  }
  for (int i = 0; i < w; i++) {
    if (mw == ws[i]) {
      js.push_back(i);
    }
  }
  int ans = mh + mw;
  for (int i = 0; i < is.size(); i++) {
    for (int j = 0; j < js.size(); j++) {
      if (s.count(P(is[i], js[j]))) {
        continue;
      }
      cout << ans << endl;
      return 0;
    }
  }
  --ans;
  cout << ans << endl;
  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int mxr = -1, mxc = -1;
  vector<vector<int>> row(h), colum(w);
  vector<int> mxh, mxw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    row[hi].push_back(wi);
    colum[wi].push_back(hi);
    mxr = max(mxr, (int)row[hi].size());
    mxc = max(mxc, (int)colum[wi].size());
  }

  rep(i, h) {
    if (mxr == row[i].size())
      mxh.push_back(i);
  }

  vector<int> cnt(w, 0);
  rep(j, w) {
    if (mxc == colum[j].size()) {
      mxw.push_back(j);
      rep(k, colum[j].size()) cnt[colum[j][k]]++;
    }
  }

  int ans = 0;
  rep(i, mxh.size()) {
    if (cnt[mxh[i]] != mxw.size()) {
      ans++;
      break;
    }
  }

  ans += mxr + (mxc - 1);
  cout << ans << endl;

  return 0;
}


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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  int mxr = -1, mxc = -1;
  vector<vector<int>> row(h), colum(w);
  vector<int> mxh, mxw;
  rep(i, m) {
    int hi, wi;
    cin >> hi >> wi;
    hi--;
    wi--;
    row[hi].push_back(wi);
    colum[wi].push_back(hi);
    mxr = max(mxr, (int)row[hi].size());
    mxc = max(mxc, (int)colum[wi].size());
  }

  rep(i, h) {
    if (mxr == row[i].size())
      mxh.push_back(i);
  }

  vector<int> cnt(h, 0);
  rep(j, w) {
    if (mxc == colum[j].size()) {
      mxw.push_back(j);
      rep(k, colum[j].size()) cnt[colum[j][k]]++;
    }
  }

  int ans = 0;
  rep(i, mxh.size()) {
    if (cnt[mxh[i]] != mxw.size()) {
      ans++;
      break;
    }
  }

  ans += mxr + (mxc - 1);
  cout << ans << endl;

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, m = 0, bombs = 0;
  cin >> n >> m >> bombs;
  vector<ll> row(n, 0);
  vector<ll> col(m, 0);
  set<pair<ll, ll>> s;
  for (ll i = 0; i < bombs; ++i) {
    ll r = 0, c = 0;
    cin >> r >> c;
    --r, --c;
    s.insert({r, c});
    ++row[r], ++col[c];
  }
  ll rmax = *max_element(row.begin(), row.end());
  ll cmax = *max_element(col.begin(), col.end());
  vector<ll> row_ind, col_ind;
  for (ll i = 0; i < n; ++i) {
    if (row[i] == rmax)
      row_ind.pb(i);
  }
  for (ll i = 0; i < m; ++i) {
    if (col[i] == cmax)
      col_ind.pb(i);
  }
  ll destroyed = 0;
  for (auto i : row_ind) {
    for (auto j : col_ind) {
      if (s.count({i, j}))
        destroyed = max(destroyed, row[i] + col[j] - 1);
      else
        destroyed = max(destroyed, row[i] + col[j]);
    }
  }
  cout << destroyed;
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, m = 0, bombs = 0;
  cin >> n >> m >> bombs;
  vector<ll> row(n, 0);
  vector<ll> col(m, 0);
  set<pair<ll, ll>> s;
  for (ll i = 0; i < bombs; ++i) {
    ll r = 0, c = 0;
    cin >> r >> c;
    --r, --c;
    s.insert({r, c});
    ++row[r], ++col[c];
  }
  ll rmax = *max_element(row.begin(), row.end());
  ll cmax = *max_element(col.begin(), col.end());
  vector<ll> row_ind, col_ind;
  for (ll i = 0; i < n; ++i) {
    if (row[i] == rmax)
      row_ind.pb(i);
  }
  for (ll i = 0; i < m; ++i) {
    if (col[i] == cmax)
      col_ind.pb(i);
  }
  if (row_ind.size() * col_ind.size() > bombs) {
    cout << rmax + cmax;
    return 0;
  }
  ll destroyed = 0;
  for (auto i : row_ind) {
    for (auto j : col_ind) {
      if (s.count({i, j}))
        destroyed = max(destroyed, row[i] + col[j] - 1);
      else
        destroyed = max(destroyed, row[i] + col[j]);
    }
  }
  cout << destroyed;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

int hcnt[300005] = {};
int wcnt[300005] = {};
vector<int> hp, wp;

map<pair<int, int>, int> coors;

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int hm = 0, wm = 0;
  for (int i = 0; i < m; ++i) {
    int hh, ww;
    scanf("%d%d", &hh, &ww);

    hm = max(++hcnt[hh], hm);
    wm = max(++wcnt[ww], wm);
    coors.insert({{hh, ww}, 0});
  }

  for (int i = 1; i <= h; ++i) {
    if (hm == hcnt[i])
      hp.push_back(i);
  }

  for (int j = 1; j <= w; ++j) {
    if (wm == wcnt[j])
      wp.push_back(j);
  }
  int ans = 0;
  for (int i : hp) {
    for (int j : wp) {
      ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0));
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

int hcnt[300005] = {};
int wcnt[300005] = {};
vector<int> hp, wp;

map<pair<int, int>, int> coors;

int main() {
  int h, w;
  cin >> h >> w;
  int m;
  cin >> m;
  int hm = 0, wm = 0;
  for (int i = 0; i < m; ++i) {
    int hh, ww;
    scanf("%d%d", &hh, &ww);

    hm = max(++hcnt[hh], hm);
    wm = max(++wcnt[ww], wm);
    coors.insert({{hh, ww}, 0});
  }

  for (int i = 1; i <= h; ++i) {
    if (hm == hcnt[i])
      hp.push_back(i);
  }

  for (int j = 1; j <= w; ++j) {
    if (wm == wcnt[j])
      wp.push_back(j);
  }
  int ans = 0;
  for (int i : hp) {
    for (int j : wp) {
      ans = max(ans, hm + wm - (coors.count({i, j}) ? 1 : 0));
      if (ans == hm + wm)
        break;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define I inline void

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e6 + 7;

// How interesting!

int n, m, k;

int col[N], row[N];

vector<pair<int, int>> ed;
map<pair<int, int>, int> mp;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in", "r" , stdin) ;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    ed.push_back({u, v});
    row[u]++;
    col[v]++;
    mp[{u, v}] = 1;
  }

  std::vector<int> vecr, vecc;

  int mxr = 0, mxc = 0;

  for (int i = 1; i <= n; i++) {
    if (row[i] == mxr) {
      vecr.push_back(i);
    } else if (row[i] > mxr)
      vecr = {i}, mxr = row[i];
  }
  for (int i = 1; i <= m; i++) {
    if (col[i] == mxc) {
      vecc.push_back(i);
    } else if (col[i] > mxc)
      vecc = {i}, mxc = col[i];
  }
  int ans = 0;
  for (auto u : vecr) {
    for (auto v : vecc) {
      ans = max(row[u] + col[v] - mp[{u, v}], ans);
    }
  }

  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define I inline void

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e6 + 7;

// How interesting!

int n, m, k;

int col[N], row[N];

vector<pair<int, int>> ed;
map<pair<int, int>, int> mp;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in", "r" , stdin) ;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    ed.push_back({u, v});
    row[u]++;
    col[v]++;
    mp[{u, v}] = 1;
  }

  std::vector<int> vecr, vecc;

  int mxr = 0, mxc = 0;

  for (int i = 1; i <= n; i++) {
    if (row[i] == mxr) {
      vecr.push_back(i);
    } else if (row[i] > mxr)
      vecr = {i}, mxr = row[i];
  }
  for (int i = 1; i <= m; i++) {
    if (col[i] == mxc) {
      vecc.push_back(i);
    } else if (col[i] > mxc)
      vecc = {i}, mxc = col[i];
  }
  int ans = 0;
  for (auto u : vecr) {
    for (auto v : vecc) {
      int k = mp[{u, v}];
      ans = max(row[u] + col[v] - k, ans);
      if (!k) {
        cout << ans;
        return 0;
      }
    }
  }

  cout << ans;

  return 0;
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> vh(h + 1, 0);
  vector<int> vw(w + 1, 0);
  unordered_map<string, int> u;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vh[l]++;
    vw[r]++;
    string temp = to_string(l) + " " + to_string(r);
    u[temp]++;
  }
  int m1 = 0;
  int m2 = 0;
  for (int i = 0; i <= h; i++) {
    if (vh[i] > m1) {
      m1 = vh[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] > m2) {
      m2 = vw[i];
    }
  }
  vector<int> l1;
  vector<int> r1;
  for (int i = 0; i <= h; i++) {
    if (vh[i] == m1) {
      l1.push_back(i);
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] == m2) {
      r1.push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < l1.size(); i++) {
    for (int j = 0; j < r1.size(); j++) {

      string temp = to_string(l1[i]) + " " + to_string(r1[j]);
      if (u.find(temp) != u.end()) {
        ans = max(ans, m1 + m2 - 1);
      } else {
        ans = max(ans, m1 + m2);
      }
    }
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> vh(h + 1, 0);
  vector<int> vw(w + 1, 0);
  unordered_map<string, int> u;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    vh[l]++;
    vw[r]++;
    string temp = to_string(l) + " " + to_string(r);
    u[temp]++;
  }
  int m1 = 0;
  int m2 = 0;
  for (int i = 0; i <= h; i++) {
    if (vh[i] > m1) {
      m1 = vh[i];
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] > m2) {
      m2 = vw[i];
    }
  }
  vector<int> l1;
  vector<int> r1;
  for (int i = 0; i <= h; i++) {
    if (vh[i] == m1) {
      l1.push_back(i);
    }
  }
  for (int i = 0; i <= w; i++) {
    if (vw[i] == m2) {
      r1.push_back(i);
    }
  }
  int ans = 0;
  for (int i = 0; i < l1.size(); i++) {
    for (int j = 0; j < r1.size(); j++) {

      string temp = to_string(l1[i]) + " " + to_string(r1[j]);
      if (u.find(temp) != u.end()) {
        ans = max(ans, m1 + m2 - 1);
      } else {
        ans = max(ans, m1 + m2);
        break;
      }
    }
  }
  cout << ans << "\n";
}
Problem p02580 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll h, w, m, a, b;
vector<ll> v, v1;
unordered_map<ll, ll> r, c;
unordered_map<ll, ll> mm;

void solve() {
  cin >> h >> w >> m;
  ll mr = 0, mc = 0;
  while (m--) {
    cin >> a >> b;
    ll t = a * 1e9 + b;
    mm[t]++;
    r[a]++;
    c[b]++;
    mr = max(mr, r[a]);
    mc = max(mc, c[b]);
  }
  for (ll i = 1; i <= h; i++) {
    if (r[i] == mr)
      v.pb(i);
  }
  for (ll i = 1; i <= w; i++) {
    if (c[i] == mc)
      v1.pb(i);
  }
  ll ans = 0;
  for (ll i = 0; i < v.size(); i++) {
    for (ll j = 0; j < v1.size(); j++) {
      ll t = v[i] * 1e9 + v1[j];
      if (mm[t] == 1)
        ans = max(ans, r[v[i]] + c[v1[j]] - 1);
      else
        ans = max(ans, r[v[i]] + c[v1[j]]);
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<ll, ll>
#define endl "\n"
#define MAXN 100005
using namespace std;

ll h, w, m, a, b;
vector<ll> v, v1;
unordered_map<ll, ll> r, c;
unordered_map<ll, ll> mm;

void solve() {
  cin >> h >> w >> m;
  ll mr = 0, mc = 0;
  while (m--) {
    cin >> a >> b;
    ll t = a * 1e9 + b;
    mm[t]++;
    r[a]++;
    c[b]++;
    mr = max(mr, r[a]);
    mc = max(mc, c[b]);
  }
  for (ll i = 1; i <= h; i++) {
    if (r[i] == mr)
      v.pb(i);
  }
  for (ll i = 1; i <= w; i++) {
    if (c[i] == mc)
      v1.pb(i);
  }
  ll ans = 0;
  if (v.size() + v1.size() > 3e5) {
    cout << mr + mc << endl;
    return;
  }
  for (ll i = 0; i < v.size(); i++) {
    for (ll j = 0; j < v1.size(); j++) {
      ll t = v[i] * 1e9 + v1[j];
      if (mm[t] == 1)
        ans = max(ans, r[v[i]] + c[v1[j]] - 1);
      else
        ans = max(ans, r[v[i]] + c[v1[j]]);
    }
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}