Language: C++

// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>
using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define toUpper(x) transform(x.begin(), x.end(), x.begin(),::toupper);
#define toLower(x) transform(x.begin(), x.end(), x.begin(),::tolower);
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18+9;
const int N=1001;
int a[no]={},b[no]={},cc[no]={},suma[no]={},mat[N][N]={{0}};
stack<int> S;
stack<int> ma;

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

int poww(int x, int y, int modulo) { int res=1;while(y) { if(y%2!=0) { res*=x;res%=modulo;y--; } else { x*=x;x%=modulo;y/=2; } } return res; }  //MODULAR EXPONENTIATION
bool comp(int a, int b) {
    return (a < b);   // MAXIMUM
    return (a > b);   // MINIMUM
}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

vi adj[no],prime;
int used[no]={},q=1,t=1;
int dist[no]={},c_comp[no]={},siz;

bool check(int x, int y) {
    bool f=false;
    for(int v : adj[x]) {
        if(v==y) {f=true;break;}
    }
    if(!f) return false;
    for(int v : adj[y]) {
        if(v==x) {return true;}
    }
    return false;
}

/**/
void solve (){
    int n,x,m;
    cin>>n>>m>>x;
    int row[n+1]={0},col[m+1]={0};
    map<int,int> mapp;
    int cou=0;
    for(int i=0 ; i<x ; i++) {
        int p,q;
        cin>>p>>q;
        mat[p%N][q%N]++;
        //adj[q].PB(p);
        row[p]++;
        col[q]++;
        cou++;
    }
    int mr=*max_element(row,row+n+1);
    int prr=max_element(row,row+n+1)-row;
    int pcc=max_element(col,col+m+1)-col;
    vi pr,pc;
    int mc=*max_element(col,col+m+1);
    for(int i=1 ; i<=n ; i++) {
        if(mr==row[i]) {
            pr.PB(i);
        }
    }
    for(int i=1 ; i<=m ; i++) {
        if(mc==col[i]) {
            pc.PB(i);
        }
    }
    int sr=pr.size();
    int sc=pc.size();
    bool f=true;
    int kk=n*m;
    if(cou>(kk-n-m) && cou>modulo) {cout<<mr+mc-1; return ;}
    else {
    for(int i=0 ; i<sr ; i++) {
        for(int j=0 ; j<sc ; j++){
            int xx=pr[i],yy=pc[j];
            if(check(xx,yy)) {}
            else {
                f=false;break;
            }
        }
    }
    if(f) cout<<mr+mc-1;
    else cout<<mr+mc;
    }
    else {
        if(check(prr,pcc)) cout<<mr+mc-1;
        else cout<<mr+mc;
    }
    
}

void runn(){
        #ifndef ONLINE JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    }

signed main()
{
    night_rider
    //runn();
    t=1;
    //cin>>t;
    q=t;
    while(t--){
        solve();
    }
}


Compiler output:
a.cc:121:24: warning: extra tokens at end of #ifndef directive
  121 |         #ifndef ONLINE JUDGE
      |                        ^~~~~
a.cc: In function 'void solve()':
a.cc:113:5: error: 'else' without a previous 'if'
  113 |     else {
      |     ^~~~