Language: C++

#include <bits/stdc++.h>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long int
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

ll n, d, x[100001], y[100001], co[1010][1010], ans, memo;
ll mel, mer, meu, med;
bool ka[1010][1010];//(n, n-1);true
int main(){
	cin >> n >> d;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		co[x[i]%d][y[i]%d]++;
	}
	for(int i=0;i<d;i++){
		for(int j=0;j<d;j++){
			if((sqrt(co[i][j])+1)*sqrt(co[i][j])<co[i][j]){
				co[i][j] = sqrt(co[i][j])+1;
			}else if(sqrt(co[i][j])*sqrt(co[i][j])==co[i][j]){
				co[i][j] = sqrt(co[i][j]);
			}else{
				co[i][j] = sqrt(co[i][j])+1;
				ka[i][j] = true;
			}
			memo = max(memo, co[i][j]);
		}
	}

	for(ll i=0;i<d;i++){
		for(ll j=0;j<d;j++){
			if(memo == co[i][j]){
				mel[0] = min(mel, i);
				mer[0] = max(mer, i+(sqrt(co[i][j])+1)*d);
				meu[0] = max(meu, j+(sqrt(co[i][j])+1)*d);
				med[0] = min(med, j);

				mel[1] = min(mel, i);
				mer[1] = max(mer, i+(sqrt(co[i][j])+1)*d);
				meu[1] = max(meu, j);
				med[1] = min(med, j-(sqrt(co[i][j])+1)*d);

				mel[1] = min(mel, i-(sqrt(co[i][j])+1)*d);
				mer[1] = max(mer, i);
				meu[1] = max(meu, j+(sqrt(co[i][j])+1)*d);
				med[1] = min(med, j);

				mel[1] = min(mel, i-(sqrt(co[i][j])+1)*d);
				mer[1] = max(mer, i);
				meu[1] = max(meu, j);
				med[1] = min(med, j-(sqrt(co[i][j])+1)*d);
			}
		}
	}

	ans = 1e+10;
	for(ll i=0;i<4;i++){
		ans = min(ans, max(mer[i]-mel[i], meu[i]-med[i]));
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:41:36: error: invalid types 'long long int[int]' for array subscript
   41 |                                 mel[0] = min(mel, i);
      |                                    ^
a.cc:42:36: error: invalid types 'long long int[int]' for array subscript
   42 |                                 mer[0] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                    ^
a.cc:42:45: error: no matching function for call to 'max(long long int&, __gnu_cxx::__enable_if<true, double>::__type)'
   42 |                                 mer[0] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:42:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   42 |                                 mer[0] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:42:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |                                 mer[0] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:43:36: error: invalid types 'long long int[int]' for array subscript
   43 |                                 meu[0] = max(meu, j+(sqrt(co[i][j])+1)*d);
      |                                    ^
a.cc:43:45: error: no matching function for call to 'max(long long int&, __gnu_cxx::__enable_if<true, double>::__type)'
   43 |                                 meu[0] = max(meu, j+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:43:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   43 |                                 meu[0] = max(meu, j+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:43:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |                                 meu[0] = max(meu, j+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:44:36: error: invalid types 'long long int[int]' for array subscript
   44 |                                 med[0] = min(med, j);
      |                                    ^
a.cc:46:36: error: invalid types 'long long int[int]' for array subscript
   46 |                                 mel[1] = min(mel, i);
      |                                    ^
a.cc:47:36: error: invalid types 'long long int[int]' for array subscript
   47 |                                 mer[1] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                    ^
a.cc:47:45: error: no matching function for call to 'max(long long int&, __gnu_cxx::__enable_if<true, double>::__type)'
   47 |                                 mer[1] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:47:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   47 |                                 mer[1] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:47:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |                                 mer[1] = max(mer, i+(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:48:36: error: invalid types 'long long int[int]' for array subscript
   48 |                                 meu[1] = max(meu, j);
      |                                    ^
a.cc:49:36: error: invalid types 'long long int[int]' for array subscript
   49 |                                 med[1] = min(med, j-(sqrt(co[i][j])+1)*d);
      |                                    ^
a.cc:49:45: error: no matching function for call to 'min(long long int&, __gnu_cxx::__enable_if<true, double>::__type)'
   49 |                                 med[1] = min(med, j-(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:49:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'})
   49 |                                 med[1] = min(med, j-(sqrt(co[i][j])+1)*d);
      |                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:49:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   49 |                                 med[1] = min(med, j-(sqrt(co[i][j])+1)*d);
      |                                          ~~~