Language: C++

//﻿#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>
#include <climits>
#include <sstream>

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define pii pair<int, int>
#define fi(n) for(int i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define RFOR(i, k, n) for(int i = (k); i >= (n); i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define umin(a, b) a = min(a, b)
#define umax(a, b) a = max(a, b)

const int INF = INT_MAX;
const int mod = 1e9 + 7;
const long long LINF = LLONG_MAX;

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	fi(n)
		cin >> v[i];
	sort(all(v));
	int answ = 0;
	int k = 0;
	v.push_back(INF);
	while (k < n)
	{
		auto it = upper_bound(all(v), v[k] + 2);
		umax(answ, it - v.begin() - k);
		k = upper_bound(all(v), v[k]) - v.begin();
	}
	cout << answ << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:27: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
   32 | #define umax(a, b) a = max(a, b)
      |                        ~~~^~~~~~
a.cc:54:17: note: in expansion of macro 'umax'
   54 |                 umax(answ, it - v.begin() - k);
      |                 ^~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:5:
/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:32:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
   32 | #define umax(a, b) a = max(a, b)
      |                        ~~~^~~~~~
a.cc:54:17: note: in expansion of macro 'umax'
   54 |                 umax(answ, it - v.begin() - k);
      |                 ^~~~
/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,
                 from a.cc:6:
/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:32:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   32 | #define umax(a, b) a = max(a, b)
      |                        ~~~^~~~~~
a.cc:54:17: note: in expansion of macro 'umax'
   54 |                 umax(answ, it - v.begin() - k);
      |                 ^~~~