Language: C++

int main()
{
    int H, W;
    long long M;

    //ifstream myfile;
    //myfile.open("sample.txt");

    cin >> H >> W >> M;
    vector<int> cnth(H), cntw(W);
    vector<pair<int, int>> colcount, rowcount;
    set<pair<int, int>> s;

    while (M--)
    {
        int a, b;
        cin >> a >> b;
        cnth[--a]++;
        cntw[--b]++;
        s.insert(make_pair(--a, --b));
    }
    //myfile.close();

    for (int i = 0; i < H; i++)
    {
        colcount.push_back({cnth[i], i});
    }
    for (int i = 0; i < W; i++)
    {
        rowcount.push_back({cntw[i], i});
    }
    sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;}); 
    sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
	
  	int max_targets = colcount[0].first + rowcount[0].first;
    //cout << "The max target is " << max_targets << endl;
    int col = 0;
    int row = 0;
    int overcount = 0;

    while (col + 1 < H && colcount[col].first >= colcount[col + 1].first)
    {
        while (row + 1 < W && rowcount[row].first >= rowcount[row + 1].first)
        {
            if (s.find({col, row}) == s.end())
            {
                cout << max_targets << endl;
                return 0;
            }
            row++;
        }
        col++;
    }
    cout << max_targets-1; //- overcount;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:5: error: 'cin' was not declared in this scope
    9 |     cin >> H >> W >> M;
      |     ^~~
a.cc:10:5: error: 'vector' was not declared in this scope
   10 |     vector<int> cnth(H), cntw(W);
      |     ^~~~~~
a.cc:10:12: error: expected primary-expression before 'int'
   10 |     vector<int> cnth(H), cntw(W);
      |            ^~~
a.cc:11:12: error: 'pair' was not declared in this scope
   11 |     vector<pair<int, int>> colcount, rowcount;
      |            ^~~~
a.cc:11:17: error: expected primary-expression before 'int'
   11 |     vector<pair<int, int>> colcount, rowcount;
      |                 ^~~
a.cc:12:5: error: 'set' was not declared in this scope
   12 |     set<pair<int, int>> s;
      |     ^~~
a.cc:12:14: error: expected primary-expression before 'int'
   12 |     set<pair<int, int>> s;
      |              ^~~
a.cc:18:9: error: 'cnth' was not declared in this scope
   18 |         cnth[--a]++;
      |         ^~~~
a.cc:19:9: error: 'cntw' was not declared in this scope
   19 |         cntw[--b]++;
      |         ^~~~
a.cc:20:9: error: 's' was not declared in this scope
   20 |         s.insert(make_pair(--a, --b));
      |         ^
a.cc:20:18: error: 'make_pair' was not declared in this scope
   20 |         s.insert(make_pair(--a, --b));
      |                  ^~~~~~~~~
a.cc:26:9: error: 'colcount' was not declared in this scope
   26 |         colcount.push_back({cnth[i], i});
      |         ^~~~~~~~
a.cc:26:29: error: 'cnth' was not declared in this scope
   26 |         colcount.push_back({cnth[i], i});
      |                             ^~~~
a.cc:30:9: error: 'rowcount' was not declared in this scope
   30 |         rowcount.push_back({cntw[i], i});
      |         ^~~~~~~~
a.cc:30:29: error: 'cntw' was not declared in this scope
   30 |         rowcount.push_back({cntw[i], i});
      |                             ^~~~
a.cc:32:10: error: 'colcount' was not declared in this scope
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |          ^~~~~~~~
a.cc:32:47: error: 'pair' is not a type
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                               ^~~~
a.cc:32:51: error: expected ',' or '...' before '<' token
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                   ^
a.cc: In lambda function:
a.cc:32:89: error: 'x' was not declared in this scope
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                                                         ^
a.cc:32:99: error: 'y' was not declared in this scope
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                                                                   ^
a.cc: In function 'int main()':
a.cc:32:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   32 |     sort(colcount.begin(), colcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |     ^~~~
      |     short
a.cc:33:10: error: 'rowcount' was not declared in this scope
   33 |     sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |          ^~~~~~~~
a.cc:33:47: error: 'pair' is not a type
   33 |     sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                               ^~~~
a.cc:33:51: error: expected ',' or '...' before '<' token
   33 |     sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                   ^
a.cc: In lambda function:
a.cc:33:89: error: 'x' was not declared in this scope
   33 |     sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                                                         ^
a.cc:33:99: error: 'y' was not declared in this scope
   33 |     sort(rowcount.begin(), rowcount.end(), [](pair<int,int> x, pair<int,int> y){ return x.first > y.first;});
      |                                                                                                   ^
a.cc: In function 'int main()':
a.cc:45:17: error: 's' was not declared in this scope
   45 |             if (s.find({col, row}) == s.end())
      |                 ^
a.cc:47:17: error: 'cout' was not declared in this scope
   47 |                 cout << max_targets << endl;
      |                 ^~~~
a.cc:47:40: error: 'endl' was not declared in this scope
   47 |                 cout << max_targets << endl;
      |                                        ^~~~
a.cc:54:5: error: 'cout' was not declared in this scope
   54 |     cout << max_targets-1; //- overcount;
      |     ^~~~