Language: C++

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

using P=pair<int,int>;
void solve()
{
	int h,w,m;
	cin>>h>>w>>m;
	vector<int>x(m),y(m),r(h),c(w);
	map<P,int>mp;
	rep(i,m){
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
		r[x[i]]++;
		c[y[i]]++;
	}
	int maxr=*max_element(all(r)),maxc=*max_element(all(c));
	ll a=0,b=0;
	rep(i,h){
		if(maxr==r[i])++a;
	}
	rep(i,w){
		if(maxc==c[i])++b;
	}
	int ans=maxr+maxc;
	ll cnt=0;
	rep(i,m){
		if(r[x[i]]==maxr&&c[y[i]]==maxc)++cnt;
	}
	if(cnt>=a*b)ans--;
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Compiler output:
a.cc:66:14: error: redefinition of 'constexpr const ll mod'
   66 | constexpr ll mod = 1e9 + 7;
      |              ^~~
a.cc:12:14: note: 'constexpr const ll mod' previously defined here
   12 | constexpr ll mod = 1e9 + 7;
      |              ^~~
a.cc:67:14: error: redefinition of 'constexpr const ll INF'
   67 | constexpr ll INF = 1LL << 60;
      |              ^~~
a.cc:13:14: note: 'constexpr const ll INF' previously defined here
   13 | constexpr ll INF = 1LL << 60;
      |              ^~~
a.cc:70:13: error: redefinition of 'template<class T> bool chmin(T&, T)'
   70 | inline bool chmin(T &a, T b)
      |             ^~~~~
a.cc:16:13: note: 'template<class T> bool chmin(T&, T)' previously declared here
   16 | inline bool chmin(T &a, T b)
      |             ^~~~~
a.cc:80:13: error: redefinition of 'template<class T> bool chmax(T&, T)'
   80 | inline bool chmax(T &a, T b)
      |             ^~~~~
a.cc:26:13: note: 'template<class T> bool chmax(T&, T)' previously declared here
   26 | inline bool chmax(T &a, T b)
      |             ^~~~~
a.cc:90:4: error: redefinition of 'll gcd(ll, ll)'
   90 | ll gcd(ll n, ll m)
      |    ^~~
a.cc:36:4: note: 'll gcd(ll, ll)' previously defined here
   36 | ll gcd(ll n, ll m)
      |    ^~~
a.cc:102:4: error: redefinition of 'll lcm(ll, ll)'
  102 | ll lcm(ll n, ll m)
      |    ^~~
a.cc:48:4: note: 'll lcm(ll, ll)' previously defined here
   48 | ll lcm(ll n, ll m)
      |    ^~~
a.cc:150:5: error: redefinition of 'int main()'
  150 | int main()
      |     ^~~~
a.cc:140:5: note: 'int main()' previously defined here
  140 | int main()
      |     ^~~~