Language: C++

#include<iostream>

using namespace std;

const int max = 500000;
const int inf = 1000000001;
long long counter = 0;
int L[max / 2 + 2], R[max / 2 + 2];

void merge(int a[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	int i, j, k;
	for (i = 0; i < n1; i++)L[i] = a[left + i];
	for (i = 0; i < n2; i++)R[i] = a[mid + i];
	L[n1] = R[n2] = inf;
	i = j = 0;
	for (k = left; k < right; k++)
	{
		if (L[i] <= R[j])
		{
			a[k] = L[i];
			i++;
		}
		else
		{
			a[k] = R[j];
			j++;
		}
		counter++;
	}
}

void mergesort(int a[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergesort(a, left, mid);
		mergesort(a, mid, right);
		merge(a, left, mid, right);
	}
}

int main()
{
	int n, i;
	cin >> n;
	int* s = new int[n];
	for (i = 0; i < n; i++)cin >> s[i];
	mergesort(s, 0, n);
	for (i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << s[i];
	}
	cout << endl << counter << endl;
    return 0;
}

Compiler output:
a.cc:8:7: error: reference to 'max' is ambiguous
    8 | int L[max / 2 + 2], R[max / 2 + 2];
      |       ^~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:5:11: note:                 'const int max'
    5 | const int max = 500000;
      |           ^~~
a.cc:8:23: error: reference to 'max' is ambiguous
    8 | int L[max / 2 + 2], R[max / 2 + 2];
      |                       ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:5:11: note:                 'const int max'
    5 | const int max = 500000;
      |           ^~~
a.cc: In function 'void merge(int*, int, int, int)':
a.cc:15:33: error: 'L' was not declared in this scope
   15 |         for (i = 0; i < n1; i++)L[i] = a[left + i];
      |                                 ^
a.cc:16:33: error: 'R' was not declared in this scope
   16 |         for (i = 0; i < n2; i++)R[i] = a[mid + i];
      |                                 ^
a.cc:17:9: error: 'L' was not declared in this scope
   17 |         L[n1] = R[n2] = inf;
      |         ^
a.cc:17:17: error: 'R' was not declared in this scope
   17 |         L[n1] = R[n2] = inf;
      |                 ^