Language: C++

#include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,head,n) for(int i=(head);i<n;i++)
#define int long long
#define F first
#define S second
#define pb push_back
#define p2(n) (1<<(n))
#define lg2(n) __lg(n)
using namespace std;
using pii = pair<long long,long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);
const int N = 3e5+10;

int n,m,k;
set<pii>s;
map<int,int> x;
map<int,int> y;
int mx,my;
vector<int>anx,any;

void solve(){
    cin >> n >> m >> k;
    rep(i,0,k){
        int a,b; cin >> a >> b;
        x[a]++; y[b]++;
        mx = max(mx,x[a]);
        my = max(my,y[b]);
        s.insert({a,b});
    }
    int sx = 0,sy = 0;
    for(auto i:x){
        if(i.S==mx){
            sx++;
            anx.pb(i.F);
        }
    }
    for(auto i:y){
        if(i.S==my){
            sy++;
            any.pb(i.F);
        }
    }
    if(sx*sy>k)
        cout << mx+my << '\n';
    else{
        for(auto i:anx){
            for(auto j:any){
                if(!s.count({i,j})){
                    cout << mx+my << '\n';
                    return;
                }
            }
        }
        cout << mx+my-1 << '\n';
    } 
}

signed main(){
    Rushia_mywife
    solve();
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:45:13: error: reference to 'any' is ambiguous
   45 |             any.pb(i.F);
      |             ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:77,
                 from a.cc:1:
/usr/include/c++/14/any:81:9: note: candidates are: 'class std::any'
   81 |   class any
      |         ^~~
a.cc:24:16: note:                 'std::vector<long long int> any'
   24 | vector<int>anx,any;
      |                ^~~
a.cc:52:24: error: reference to 'any' is ambiguous
   52 |             for(auto j:any){
      |                        ^~~
/usr/include/c++/14/any:81:9: note: candidates are: 'class std::any'
   81 |   class any
      |         ^~~
a.cc:24:16: note:                 'std::vector<long long int> any'
   24 | vector<int>anx,any;
      |                ^~~
a.cc:53:28: error: no matching function for call to 'std::set<std::pair<long long int, long long int> >::count(<brace-enclosed initializer list>)'
   53 |                 if(!s.count({i,j})){
      |                     ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158:
/usr/include/c++/14/bits/stl_set.h:756:9: note: candidate: 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >]'
  756 |         count(const _Kt& __x) const
      |         ^~~~~
/usr/include/c++/14/bits/stl_set.h:756:9: note:   template argument deduction/substitution failed:
a.cc:53:28: note:   couldn't deduce template parameter '_Kt'
   53 |                 if(!s.count({i,j})){
      |                     ~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_set.h:750:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::pair<long long int, long long int>; _Compare = std::less<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::pair<long long int, long long int> >; size_type = long unsigned int; key_type = std::pair<long long int, long long int>]'
  750 |       count(const key_type& __x) const
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:750:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::set<std::pair<long long int, long long int> >::key_type&' {aka 'const std::pair<long long int, long long int>&'}
  750 |       count(const key_type& __x) const
      |             ~~~~~~~~~~~~~~~~^~~