criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <stdio.h>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    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]=SENTINEL;
    int i=0,j=0;
    for(int k=left; k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }
        else {
            A[k]=R[j++];
        }
    }
}

void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}
int main(){
    int A[MAX],n,i;
    cnt=0;
    cin >> n;
    for(i=0;i<n;i++)cin >> A[i];
    mergeSort(A,n,0,n);

    for(i=0;i<n;i++){
        if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt <<endl;

    return 0;
    }


Compiler output:
a.cc: In function 'void merge(int*, int, int, int, int)':
a.cc:11:9: error: 'i' was not declared in this scope
   11 |     for(i=0;i<n1;i++)L[i]=A[left+i];
      |         ^
a.cc:12:9: error: 'i' was not declared in this scope
   12 |     for(i=0;i<n2;i++)R[i]=A[mid+i];
      |         ^
a.cc: In function 'int main()':
a.cc:37:5: error: 'cin' was not declared in this scope
   37 |     cin >> n;
      |     ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <stdio.h>
  +++ |+#include <iostream>
    2 | using namespace std;
a.cc:42:14: error: 'cout' was not declared in this scope
   42 |         if(i)cout << " ";
      |              ^~~~
a.cc:42:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:9: error: 'cout' was not declared in this scope
   43 |         cout << A[i];
      |         ^~~~
a.cc:43:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:45:5: error: 'cout' was not declared in this scope
   45 |     cout << endl;
      |     ^~~~
a.cc:45:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:45:13: error: 'endl' was not declared in this scope
   45 |     cout << endl;
      |             ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <stdio.h>
  +++ |+#include <ostream>
    2 | using namespace std;
Language: C++

#include <stdio.h>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;

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

void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}
int main(){
    int A[MAX],n,i;
    cnt=0;
    cin >> n;
    for(i=0;i<n;i++)cin >> A[i];
    mergeSort(A,n,0,n);

    for(i=0;i<n;i++){
        if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt <<endl;

    return 0;
    }


Compiler output:
a.cc: In function 'int main()':
a.cc:37:5: error: 'cin' was not declared in this scope
   37 |     cin >> n;
      |     ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <stdio.h>
  +++ |+#include <iostream>
    2 | using namespace std;
a.cc:42:14: error: 'cout' was not declared in this scope
   42 |         if(i)cout << " ";
      |              ^~~~
a.cc:42:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:9: error: 'cout' was not declared in this scope
   43 |         cout << A[i];
      |         ^~~~
a.cc:43:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:45:5: error: 'cout' was not declared in this scope
   45 |     cout << endl;
      |     ^~~~
a.cc:45:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:45:13: error: 'endl' was not declared in this scope
   45 |     cout << endl;
      |             ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <stdio.h>
  +++ |+#include <ostream>
    2 | using namespace std;
Language: C++

#include <stdio.h>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[MAX/2+2],R[MAX/2+2];
int cnt;

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

void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}
int main(){
    int A[MAX],n,i;
    int cin,cout,endl;
    cnt=0;
    cin >> n;
    for(i=0;i<n;i++)cin >> A[i];
    mergeSort(A,n,0,n);

    for(i=0;i<n;i++){
        if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt <<endl;

    return 0;
    }


Compiler output:
a.cc: In function 'int main()':
a.cc:43:19: error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'
   43 |         if(i)cout << " ";
      |              ~~~~ ^~ ~~~
      |              |       |
      |              int     const char [2]
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int l[MAX/2+2],R[MAX/2+2];
int cnt;

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

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

int main(){
    int A[MAX],n,i;
    cnt=0;
    cin>>n;
    for(i=0;i<n;i++)cin>>A[i];
    mergeSort(A,n,0,n);
    for(i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'void merge(int*, int, int, int, int)':
a.cc:12:26: error: 'L' was not declared in this scope
   12 |     for(int i=0;i<n1;i++)L[i]=A[left+i];
      |                          ^
a.cc:13:5: error: 'L' was not declared in this scope
   13 |     L[n1]=R[n2]=SENTINEL;
      |     ^
a.cc:14:13: error: 'j' was not declared in this scope
   14 |     int i=0;j=0;
      |             ^
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

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

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

int main(){
    int A[MAX],n,i;
    cnt=0;
    cin>>n;
    for(i=0;i<n;i++)cin>>A[i];
    mergeSort(A,n,0,n);
    for(i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'void merge(int*, int, int, int, int)':
a.cc:14:13: error: 'j' was not declared in this scope
   14 |     int i=0;j=0;
      |             ^
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

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

void MergeSort(int A[], int n, int left, int right){
     if(left + 1 < right){
          int mid = (left + right) / 2;
          mergeSort(A, n, left, mid);
          mergeSort(A, n, mid, right);
          merge(A, n, left, mid, right);
    }
}

int main(void){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for( i = 0; i < n; ++i) cin >> A[i];

    mergeSort(A, n, 0, n);

    for( i = 0; i < n; ++i){
       if( i ) cout << " ";
       cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;
    return 0;
}
}
     }
}


Compiler output:
a.cc: In function 'void MergeSort(int*, int, int, int)':
a.cc:26:11: error: 'mergeSort' was not declared in this scope; did you mean 'MergeSort'?
   26 |           mergeSort(A, n, left, mid);
      |           ^~~~~~~~~
      |           MergeSort
a.cc: In function 'int main()':
a.cc:39:5: error: 'mergeSort' was not declared in this scope; did you mean 'MergeSort'?
   39 |     mergeSort(A, n, 0, n);
      |     ^~~~~~~~~
      |     MergeSort
a.cc: At global scope:
a.cc:50:1: error: expected declaration before '}' token
   50 | }
      | ^
a.cc:51:6: error: expected declaration before '}' token
   51 |      }
      |      ^
a.cc:52:1: error: expected declaration before '}' token
   52 | }
      | ^
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

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

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

int main(void){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for( i = 0; i < n; ++i) cin >> A[i];

    mergeSort(A, n, 0, n);

    for( i = 0; i < n; ++i){
       if( i ) cout << " ";
       cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;
    return 0;
}
}
     }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:5: error: 'mergeSort' was not declared in this scope; did you mean 'MergeSort'?
   39 |     mergeSort(A, n, 0, n);
      |     ^~~~~~~~~
      |     MergeSort
a.cc: At global scope:
a.cc:50:1: error: expected declaration before '}' token
   50 | }
      | ^
a.cc:51:6: error: expected declaration before '}' token
   51 |      }
      |      ^
a.cc:52:1: error: expected declaration before '}' token
   52 | }
      | ^
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

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

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

int main(void){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for( i = 0; i < n; ++i) cin >> A[i];

    MergeSort(A, n, 0, n);

    for( i = 0; i < n; ++i){
       if( i ) cout << " ";
       cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;
    return 0;
}
}
     }
}


Compiler output:
a.cc:50:1: error: expected declaration before '}' token
   50 | }
      | ^
a.cc:51:6: error: expected declaration before '}' token
   51 |      }
      |      ^
a.cc:52:1: error: expected declaration before '}' token
   52 | }
      | ^
Language: C++

#include<stdio.h>

#define LIM 500000
#define SENTINEL 1000000001
int cnt = 0;

void merge(int A[], int left, int mid, int right) {
  int l = mid - left;
  int r = right - mid;
  int L[l], R[r];

  for ( int i = 0; i < l; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < r; i++ ) R[i] = A[mid + i];
  L[l] = R[r] = SENTINEL;

  l = r = 0;
  for ( int i = left; i < right; i++ ) {
    if (L[l] <= R[r]) {
      A[i] = L[l];
      l++;
    } else {
      A[i] = R[r];
      r++;
    }
    cnt++;
  }
}

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);
  }
}

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, A[LIM];

  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);

  mergeSort(A, 0, n);

  for ( int i = 0; i < n; i++ ) {
    if (i) printf(" ");
    printf("%d", A[i]);
  }

  printf("\n");

  printf("%d\n", cnt);

  return 0;
}



Compiler output:
a.cc:38:6: error: redefinition of 'void mergeSort(int*, int, int)'
   38 | void mergeSort(int A[], int left, int right) {
      |      ^~~~~~~~~
a.cc:29:6: note: 'void mergeSort(int*, int, int)' previously defined here
   29 | void mergeSort(int A[], int left, int right) {
      |      ^~~~~~~~~
Language: C++

#include <stdio.h>
#include <stdlib.h>
#define INF 10000000
#define MAX 500001

int n = 0;

void Merge (int *A, int l, int m, int r ) {
  int n1 = m - l;
  int n2 = r - m;

  int *a = (int *)malloc(sizeof(int) * (n1 + 1));
  int *b = (int *)malloc(sizeof(int) * (n2 + 1));

  for (int i = 0; i < n1; i++) {
    a[i] = A[l+i];
  }

  for (int i = 0; i < n2; i++) {
    b[i] = A[m+i];
  }

  a[n1] = INF;
  b[n2] = INF;

  int i = 0;
  int j = 0;

  for (int k = l; k < r; k++) {
    n++;
    if (a[i] <= b[j]) {
      A[k] = a[i];
      i++;
    }else {
      A[k] = b[j];
      j++;
    }
  }
  free(a);
  free(b);
}

void Merge_Sort (int *A, int l, int r) {
  if (l + 1 < r) {
    int m = (l + r) / 2;
    Merge_Sort(A, l, m);
    Merge_Sort(A, m, r);
    Merge(A, l, m, r);
  }
}

int main () {
  int s;
  int A[MAX];
  scanf("%d", &s);
  for (int i = 0; i < s; i++) {
    scanf("%d", &A[i]);
  }
  Merge_Sort(A, 0, s);

  for (int i = 0; i < s-1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);
  printf("%d\n", n);

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:20: error: 'i' was not declared in this scope
   64 |   printf("%d\n", A[i]);
      |                    ^
Language: C++

#include <stdio.h>
#include <stdlib.h>
#define INF 10000000
#define MAX 500001

int n = 0;

void Merge (int *A, int l, int m, int r ) {
  int n1 = m - l;
  int n2 = r - m;

  int *a = (int *)malloc(sizeof(int) * (n1 + 1));
  int *b = (int *)malloc(sizeof(int) * (n2 + 1));

  for (int i = 0; i < n1; i++) {
    a[i] = A[l+i];
  }

  for (int i = 0; i < n2; i++) {
    b[i] = A[m+i];
  }

  a[n1] = INF;
  b[n2] = INF;

  int i = 0;
  int j = 0;

  for (int k = l; k < r; k++) {
    n++;
    if (a[i] <= b[j]) {
      A[k] = a[i];
      i++;
    }else {
      A[k] = b[j];
      j++;
    }
  }
  free(a);
  free(b);
}

void Merge_Sort (int *A, int l, int r) {
  if (l + 1 < r) {
    int m = (l + r) / 2;
    Merge_Sort(A, l, m);
    Merge_Sort(A, m, r);
    Merge(A, l, m, r);
  }
}

int main () {
  int s;
  int A[MAX];
  scanf("%d", &s);
  for (int i = 0; i < s; i++) {
    scanf("%d", &A[i]);
  }
  Merge_Sort(A, 0, s);

  for (int i = 0; i < s - 1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);
  printf("%d\n", n);

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:20: error: 'i' was not declared in this scope
   64 |   printf("%d\n", A[i]);
      |                    ^
Language: C++

#include <cstdio>
#include <iostream>
#include <limit>
using namespace std;

int s[500000];
int c = 0;
void merge(int left , int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;

	int *l = new int[n1 + 1];
	int *r = new int[n2 + 1];

	for (int i = 0; i < n1; i++)
	{
		l[i] = s[left + i];
	}

	for (int i = 0; i < n2; i++)
	{
		r[i] = s[mid + i];
	}

	l[n1] = numeric_limits<int>::max();
	r[n2] = numeric_limits<int>::max();

	int i = 0;
	int j = 0;

	for (int k = left; k < right; k++)
	{
		if (l[i] <= r[j])
		{
			s[k] = l[i];
			i++;
		}
		else
		{
			s[k] = r[j];
			j++;
		}
		c++;
	}
	delete[] l;
	delete[] r;

}

void mergeSort(int left,int right)
{
	int mid;

	if (left + 1 < right)
	{
		mid = (left + right) / 2;
		mergeSort(left,mid);
		mergeSort(mid,right);
		merge(left, mid, right);
	}
}
void B()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}


	mergeSort(0,n);
	for (int i = 0; i < n; i++)
	{
		cout << s[i];
		if (i != n - 1)
		{
			cout << " ";
		}
	}

	cout << endl;
	cout << c << endl;
}
int main()
{
	//A();
	B();
	return 0;
}

Compiler output:
a.cc:3:10: fatal error: limit: No such file or directory
    3 | #include <limit>
      |          ^~~~~~~
compilation terminated.
Language: C++

#include<iostream>
using namespace std;

int s[500000];

int marge(int left, int right) {
	if (right-1 == left) {
		return 0;
	}
	int mid = (left + right) / 2;
	count += marge(left, mid);
	count += marge(mid, right);
	int count = 0, index, i, j = mid, t[500000];
	index = i = left;
	while(i < mid && j < right){
		if (s[i] < s[j]) {
			t[index++] = s[i++];
		} else {
			t[index++] = s[j++];
		}
	}
	while (j < right) t[index++] = s[j++];
	while(i < mid) t[index++] = s[i++];
	j = left;
	for (int i = left; i < right; i++,j++) {
		s[i] = t[j];
	}
	return count + right - left;
}

int main(void) {
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int count = marge(0, n);

	for (int i = 0; i < n; i++) {
		cout << s[i];
		if(i != n - 1) cout << " ";
	}
	cout << endl << count << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int marge(int, int)':
a.cc:11:9: error: 'count' was not declared in this scope
   11 |         count += marge(left, mid);
      |         ^~~~~
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for(int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for(int k = left; k < right: k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

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

int main(){
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for(i = 0; i < n; i++){
    if(i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}

Compiler output:
a.cc: In function 'void merge(int*, int, int, int, int)':
a.cc:18:21: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   18 |   for(int k = left; k < right: k++){
      |                     ^
a.cc:18:30: error: found ':' in nested-name-specifier, expected '::'
   18 |   for(int k = left; k < right: k++){
      |                              ^
      |                              ::
a.cc:18:25: error: 'right' is not a class, namespace, or enumeration
   18 |   for(int k = left; k < right: k++){
      |                         ^~~~~
a.cc:26:1: error: expected primary-expression before '}' token
   26 | }
      | ^
a.cc:25:4: error: expected ';' before '}' token
   25 |   }
      |    ^
      |    ;
   26 | }
      | ~   
a.cc:26:1: error: expected primary-expression before '}' token
   26 | }
      | ^
a.cc:25:4: error: expected ')' before '}' token
   25 |   }
      |    ^
      |    )
   26 | }
      | ~   
a.cc:18:6: note: to match this '('
   18 |   for(int k = left; k < right: k++){
      |      ^
a.cc:26:1: error: expected primary-expression before '}' token
   26 | }
      | ^
Language: C++

#include<stdio.h>
#include<stdlib.h>
#define N 500000
#define SENTINEL 1000000000

void mergesort( int,int);
void merge(int,int,int);

int A[N],count=0;
main()
{
  int left,right,mid,i,n;

  scanf("%d",&n);
 
  left = 0;
  right = n;
  mid = (left + right)/2;

  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  mergesort(left,mid);  /*????????§DEVIDE??????*/
  mergesort(mid,right);
  merge(left,mid,right);

  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i == n-1)break;
      printf(" ");
    }
  printf("\n%d\n",count);
return 0;
}


void mergesort(int l,int r )
{
  int m;

  if(l+1<r)
    {
      m = (l + r)/2;
      mergesort(l,m);
      mergesort(m,r);
      merge(l,m,r);
    }
}


void merge(int l,int m,int r)
{
  int n1,n2,k,j,i;
  int *L,*R;
  n1 = m - l;
  n2 = r - m;

  L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
  R = malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++)
    {
      L[i] = A[l+i];
    }

  L[n1] = SENTINEL;

  for(i=0;i<n2;i++)
    {
      R[i] = A[m+i];
    }

  R[n2] = SENTINEL;

  j = 0;
  k = 0;

  for(i=l;i<r;i++)
    {
      if(L[j] <=R[k])
	{
	  A[i] = L[j];
	  j++;
	  count++;
	}
      else
	{
	  A[i] = R[k];
	  k++;
	  count++;
	}

    }

}

Compiler output:
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~
a.cc: In function 'void merge(int, int, int)':
a.cc:60:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   60 |   L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
a.cc:61:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   61 |   R = malloc(sizeof(int)*(n2+1));
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
Language: C++

#include<stdio.h>
#include<stdlib.h>
#define N 500000
#define SENTINEL 100000000

void mergesort( int,int);
void merge(int,int,int);

int A[N],count=0;
main()
{
  int left,right,mid,i,n;

  scanf("%d",&n);
 
  left = 0;
  right = n;
  mid = (left + right)/2;

  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  mergesort(left,mid);  /*????????§DEVIDE??????*/
  mergesort(mid,right);
  merge(left,mid,right);

  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i == n-1)break;
      printf(" ");
    }
  printf("\n%d\n",count);
return 0;
}


void mergesort(int l,int r )
{
  int m;

  if(l+1<r)
    {
      m = (l + r)/2;
      mergesort(l,m);
      mergesort(m,r);
      merge(l,m,r);
    }
}


void merge(int l,int m,int r)
{
  int n1,n2,k,j,i;
  int *L,*R;
  n1 = m - l;
  n2 = r - m;

  L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
  R = malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++)
    {
      L[i] = A[l+i];
    }

  L[n1] = SENTINEL;

  for(i=0;i<n2;i++)
    {
      R[i] = A[m+i];
    }

  R[n2] = SENTINEL;

  j = 0;
  k = 0;

  for(i=l;i<r;i++)
    {
      if(L[j] <=R[k])
	{
	  A[i] = L[j];
	  j++;
	  count++;
	}
      else
	{
	  A[i] = R[k];
	  k++;
	  count++;
	}

    }

}

Compiler output:
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~
a.cc: In function 'void merge(int, int, int)':
a.cc:60:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   60 |   L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
a.cc:61:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   61 |   R = malloc(sizeof(int)*(n2+1));
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
Language: C++

#include<stdio.h>
#include<stdlib.h>
#define N 500000
#define SENTINEL 4927776

void mergesort( int,int);
void merge(int,int,int);

int A[N],count=0;
main()
{
  int left,right,mid,i,n;

  scanf("%d",&n);
 
  left = 0;
  right = n;
  mid = (left + right)/2;

  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  mergesort(left,mid);  /*????????§DEVIDE??????*/
  mergesort(mid,right);
  merge(left,mid,right);

  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i == n-1)break;
      printf(" ");
    }
  printf("\n%d\n",count);
return 0;
}


void mergesort(int l,int r )
{
  int m;

  if(l+1<r)
    {
      m = (l + r)/2;
      mergesort(l,m);
      mergesort(m,r);
      merge(l,m,r);
    }
}


void merge(int l,int m,int r)
{
  int n1,n2,k,j,i;
  int *L,*R;
  n1 = m - l;
  n2 = r - m;

  L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
  R = malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++)
    {
      L[i] = A[l+i];
    }

  L[n1] = SENTINEL;

  for(i=0;i<n2;i++)
    {
      R[i] = A[m+i];
    }

  R[n2] = SENTINEL;

  j = 0;
  k = 0;

  for(i=l;i<r;i++)
    {
      if(L[j] <=R[k])
	{
	  A[i] = L[j];
	  j++;
	  count++;
	}
      else
	{
	  A[i] = R[k];
	  k++;
	  count++;
	}

    }

}

Compiler output:
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~
a.cc: In function 'void merge(int, int, int)':
a.cc:60:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   60 |   L = malloc(sizeof(int)*(n1+1));/*SENTINEL??????????????????????????????*/
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
a.cc:61:13: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   61 |   R = malloc(sizeof(int)*(n2+1));
      |       ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void*
Language: C++

#include <stdio.h>

#define INFTY 1000000000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int count=0;

int main(){
  int i, n;
  int S[500000];

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
  }

  mergeSort(S, 0, n);

  for(i=0; i<n-1; i++){
    printf("%d ", S[i]);
  }
  printf("%d\n", S[i]);
 
  printf("%d\n", count);

  return 0;
}

void merge(int *A, int left, int mid, int right){
  int i, j, k;
  int n1, n2;
  int L[mid - left + 1], R[right - mid + 1];

  n1 = mid - left;
  n2 = right - mid;

  for( i=0; i < n1; i++){
    L[i] = A[left + i];
  }

  for( i=0; i < n2; i++){
    R[i] = A[mid + i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  i = 0;
  j = 0;

  for( k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
    count++;
  }

}

void mergeSort(int *A, int left, int right){
  int mid = n/2;

  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }

}

Compiler output:
a.cc: In function 'void mergeSort(int*, int, int)':
a.cc:68:13: error: 'n' was not declared in this scope
   68 |   int mid = n/2;
      |             ^
Language: C++

#include <math.h>
#include <iostream>

int cnt = 0;

void marge(int A[], int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;

	int L[n1 + 1], R[n2 + 1];
	for (int i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}
	L[n1] = INT_MAX;
	R[n2] = INT_MAX;

	int i = 0;
	int j = 0;
	for (int k = left; k < right; ++k) {
		A[k] = (L[i] <= R[j]) ? L[i++] : R[j++];
		++cnt;
	}
}

void marge_sort(int A[], int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		marge_sort(A, left, mid);
		marge_sort(A, mid, right);
		marge(A, left, mid, right);
	}
}

int main() {
	int n;
	std::cin >> n;
	int A[n];
	for (int i = 0; i < n; ++i) {
		std::cin >> A[i];
	}
	marge_sort(A, 0, n);

	for (int i = 0; i < n; ++i) {
		std::cout << A[i] << (i < n - 1 ? ' ' : '\n');
	}
	std::cout << cnt << std::endl;

	return 0;
}

Compiler output:
a.cc: In function 'void marge(int*, int, int, int)':
a.cc:17:17: error: 'INT_MAX' was not declared in this scope
   17 |         L[n1] = INT_MAX;
      |                 ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <iostream>
  +++ |+#include <climits>
    3 |
Language: C++

n = int(raw_input())
A = map(int, raw_input().split(" "))
count = 0

def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


    
def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right))

print " ".join(map(str, mergeSort(A)))
print count

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = int(raw_input())
      | ^
Language: C++

/* ALDS1_5_B: Merge Sort */

#include <iostream>
#include <climits>

int n_compared = 0;

void merge(int A[], int left, int mid, int right) {
    int n_left  = mid - left;
    int n_right = right - mid;
    int L[n_left], R[n_right];

    for (int i = 0; i < n_left; i++)
        L[i] = A[left + i];
    for (int i = 0; i < n_right; i++)
        R[i] = A[mid + i];
    L[n_left] = R[n_right] = std::numeric_limits<int>::max();

    int i_l = 0, i_r = 0;
    for (int i_a = left; i_a < right; i_a++) {
        A[i_a] = ( L[i_l] <= R[i_r] ) ? L[ i_l++ ] : R[ i_r++ ];
        n_compared++;
    }
}

void merge_sort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        merge_sort(A, left, mid);  // left to mid - 1
        merge_sort(A, mid, right); // mid to right - 1
        merge(A, left, mid, right);
    }
}

int main() {
    std::ios::sync_with_stdio(false);

    int n = 0;
    std::cin >> n;

    int A[n];
    for (int i = 0; i < n; i++)
        std::cin >> A[i];

    merge_sort(A, 0, n);

    std::cout << A[0];
    for (int i = 1; i < n; i++)
        std::cout << " " << A[i];
    std::cout << std::endl;
    std::cout << n_compared << std::endl;

    return 0;
}

Compiler output:
a.cc: In function 'void merge(int*, int, int, int)':
a.cc:17:35: error: 'numeric_limits' is not a member of 'std'
   17 |     L[n_left] = R[n_right] = std::numeric_limits<int>::max();
      |                                   ^~~~~~~~~~~~~~
a.cc:17:50: error: expected primary-expression before 'int'
   17 |     L[n_left] = R[n_right] = std::numeric_limits<int>::max();
      |                                                  ^~~
Language: C++

#include <cstdio>
#include <vector>

using namespace std;

namespace {

static size_t Merge(size_t* A, size_t left, size_t mid, size_t right) {
  const size_t n1 = mid - left;
  const size_t n2 = right - mid;

  vector<size_t> L(n1+1);
  vector<size_t> R(n2+1);
  for (size_t i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const size_t kInf = numeric_limits<size_t>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static size_t MergeSortInternal(size_t* A, size_t left, size_t right) {
  if (left + 1 >= right) return 0;

  const size_t mid = (left + right) / 2;
  size_t ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static size_t MergeSort(size_t* A, size_t n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

int main() {
  size_t n;
  size_t S[500000];
  scanf("%lu", &n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%lu", &S[i]);
  }

  const size_t swapped = MergeSort(S, n);
  for (size_t i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%lu", S[i]);
  }
  printf("\n");
  printf("%lu\n", swapped);

  return 0;
}

Compiler output:
a.cc: In function 'size_t {anonymous}::Merge(size_t*, size_t, size_t, size_t)':
a.cc:21:30: error: 'numeric_limits' was not declared in this scope
   21 |   static const size_t kInf = numeric_limits<size_t>::max();
      |                              ^~~~~~~~~~~~~~
a.cc:21:51: error: expected primary-expression before '>' token
   21 |   static const size_t kInf = numeric_limits<size_t>::max();
      |                                                   ^
a.cc:21:57: error: no matching function for call to 'max()'
   21 |   static const size_t kInf = numeric_limits<size_t>::max();
      |                                                    ~~~~~^~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/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:   candidate expects 2 arguments, 0 provided
/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, 0 provided
Language: C++

#include <iostream>

using std::cin;
using std::cout;

const int num = 500000;

void marge(int* data,int start,int mid,int end)
{
	int s[num/2],e[num/2];
	for (int i = 0; i < (mid-start)+1; ++i)
	{
		e[i] = INT_MAX;
		s[i] = INT_MAX;
	}
	for (size_t i = 0; i < mid-start; i++)
	{
		s[i] = data[start+i];
	}
	for (size_t i = 0; i < end-mid; i++)
	{
		e[i] = data[mid + i];
	}

	int a=0, b=0;
	for (size_t i = 0; i < end-start; i++)
	{
		if (s[a]<e[b])
		{
			data[start + i] = e[a];
			a++;
		}
		if (s[a]>e[b])
		{
			data[start + i] = e[b];
			b++;
		}
	}
}

void margesort(int *data,int start,int end)
{
	if (start + 1 < end)
	{
		int mid = (start + end) / 2;
		margesort(data,start,mid);
		margesort(data, mid, end);

		marge(data,start,mid,end);
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int a[num];
	int n;

	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	margesort(a,0,n);

	for (size_t i = 0; i < n; i++)
	{
		cout << a[i];
	}

	return 0;
}

Compiler output:
a.cc: In function 'void marge(int*, int, int, int)':
a.cc:13:24: error: 'INT_MAX' was not declared in this scope
   13 |                 e[i] = INT_MAX;
      |                        ^~~~~~~
a.cc:2:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    1 | #include <iostream>
  +++ |+#include <climits>
    2 |
Language: C++

#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 200000000
int L[MAX/2], R[MAX/2];
int cnt;
void merge(int A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[right + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0; // i is number of factor left
	int j = 0; // j is number of factor right
	for(int k = left; k < right; k++){
		cnt++;
		if(L[i] <= R[j]){
			A[k] = L[i++];
		} else {
			A[k] = R[i++];
		}
	}
}

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

int main(){
	int A[MAX], n , i;
	cnt = 0;
	
	cin >> n;
	for(i = 0; i < n; i++) cin >> A[i];
	
	mergesort(A, n, 0, n);
	
	for(i = 0; i< n; i++){
		if(i) cout <<" ";
		cout << A[i];
	}
	cout << endl;
	
	cout << cnt << endl;
	
	return 0;
}

Compiler output:
a.cc: In function 'void mergeSort(int*, int, int, int, int)':
a.cc:28:26: error: too few arguments to function 'void mergeSort(int*, int, int, int, int)'
   28 |                 mergeSort(A, n, left, mid);
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~
a.cc:25:6: note: declared here
   25 | void mergeSort(int A[],int n, int left, int mid, int right){
      |      ^~~~~~~~~
a.cc:29:26: error: too few arguments to function 'void mergeSort(int*, int, int, int, int)'
   29 |                 mergeSort(A, n, mid, right);
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:25:6: note: declared here
   25 | void mergeSort(int A[],int n, int left, int mid, int right){
      |      ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:41:9: error: 'mergesort' was not declared in this scope; did you mean 'mergeSort'?
   41 |         mergesort(A, n, 0, n);
      |         ^~~~~~~~~
      |         mergeSort
Language: C++

#include <iostream>
#include <cstdio>

using namespace std;

int n, count;
int *S;

inline void merge(int left, int mid, int right) {
//    printf("[merge] left = %d, mid = %d, right = %d\n",
//                    left,      mid,      right);
    int n1 = mid - left, n2 = right - mid;
    int *L = new int[n1 + 1], *R = new int[n2 + 1];
    memcpy(L, S + left, sizeof(int) * n1);
    memcpy(R, S + mid, sizeof(int) * n2);
    L[n1] = R[n2] = 1e9+1;      // sentinel 

    for (int i = 0, j = 0, k = left; k < right; ++k) {
        ++count;
        if (L[i] <= R[j]) {
            S[k] = L[i++];
        }
        else {
            S[k] = R[j++];
        }
    }
    delete[] L;
    delete[] R;
}

inline void merge_sort(int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
//        printf("[merge_sort] left = %d, mid = %d, right = %d\n",
//                             left,      mid,      right);
        merge_sort(left, mid);
        merge_sort(mid, right);
        merge(left, mid, right);
    }
}

int main(void) {

    scanf("%d", &n);

    S = new int[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", S + i);
    }

    merge_sort(0, n);

    printf("%d", S[0]);
    for (int i = 1; i < n; ++i) {
        printf(" %d", S[i]);
    }
    printf("\n%d\n", count);

    delete[] S;

    return 0;
}

Compiler output:
a.cc: In function 'void merge(int, int, int)':
a.cc:14:5: error: 'memcpy' was not declared in this scope
   14 |     memcpy(L, S + left, sizeof(int) * n1);
      |     ^~~~~~
a.cc:3:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <cstdio>
  +++ |+#include <cstring>
    3 |
Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

static int count = 0;

template<typename T>
void merge_sort(T ar[], T tmp[], int n){
    m_sort(ar, tmp, 0, n - 1);
}

template<typename T>
void m_sort(T ar[], T tmp[], int left, int right){
    int mid;


    if(right > left){
        mid = (left + right) / 2;

        m_sort(ar, tmp, left, mid);
        m_sort(ar, tmp, mid + 1, right);

        merge(ar, tmp, left, mid + 1, right);
        
    }
}

template<typename T>
void merge(T ar[], T tmp[], int left, int mid, int right_last){
    int n, left_last, tmp_pos=left;

    left_last = mid - 1;
    n = right_last - left + 1;

    // ??????????????????????????§
    while (left <= left_last && mid <= right_last) {
        count++; // ???????????°
        if(ar[left] <= ar[mid]){
            tmp[tmp_pos] = ar[left];
            left++;
        }else{
            tmp[tmp_pos] = ar[mid];
            mid++;
        }
        tmp_pos++;
    }

    // ????????????
    while(left <= left_last){
        count++; // ???????????°
        tmp[tmp_pos] = ar[left];
        left++;
        tmp_pos++;
    }
    // ????????????
    while (mid <= right_last) {
        count++; // ???????????°
        tmp[tmp_pos] = ar[mid];
        mid++;
        tmp_pos++;
    }

    // tmp??????ar???
    for (int i = 0; i < n; i++) {
        ar[right_last] = tmp[right_last];
        right_last--;
    }

}
int ar[500000], tmp[500000];

int main(int argc, char const* argv[])
{
    int n;

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
    }

    merge_sort(ar, tmp, n);

    for (int i = 0; i < n - 1; i++) {
        printf("%d ", ar[i]);
    }
    printf("%d\n", ar[n-1]);
    printf("%d\n", count);

    return 0;
}

Compiler output:
a.cc: In instantiation of 'void merge_sort(T*, T*, int) [with T = int]':
a.cc:83:15:   required from here
   83 |     merge_sort(ar, tmp, n);
      |     ~~~~~~~~~~^~~~~~~~~~~~
a.cc:11:11: error: 'm_sort' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
   11 |     m_sort(ar, tmp, 0, n - 1);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:15:6: note: 'template<class T> void m_sort(T*, T*, int, int)' declared here, later in the translation unit
   15 | void m_sort(T ar[], T tmp[], int left, int right){
      |      ^~~~~~
Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

static int count = 0;


template<typename T>
void m_sort(T ar[], T tmp[], int left, int right){
    int mid;


    if(right > left){
        mid = (left + right) / 2;

        m_sort(ar, tmp, left, mid);
        m_sort(ar, tmp, mid + 1, right);

        merge(ar, tmp, left, mid + 1, right);
        
    }
}

template<typename T>
void merge_sort(T ar[], T tmp[], int n){
    m_sort(ar, tmp, 0, n - 1);
}

template<typename T>
void merge(T ar[], T tmp[], int left, int mid, int right_last){
    int n, left_last, tmp_pos=left;

    left_last = mid - 1;
    n = right_last - left + 1;

    // ??????????????????????????§
    while (left <= left_last && mid <= right_last) {
        count++; // ???????????°
        if(ar[left] <= ar[mid]){
            tmp[tmp_pos] = ar[left];
            left++;
        }else{
            tmp[tmp_pos] = ar[mid];
            mid++;
        }
        tmp_pos++;
    }

    // ????????????
    while(left <= left_last){
        count++; // ???????????°
        tmp[tmp_pos] = ar[left];
        left++;
        tmp_pos++;
    }
    // ????????????
    while (mid <= right_last) {
        count++; // ???????????°
        tmp[tmp_pos] = ar[mid];
        mid++;
        tmp_pos++;
    }

    // tmp??????ar???
    for (int i = 0; i < n; i++) {
        ar[right_last] = tmp[right_last];
        right_last--;
    }

}
int ar[500000], tmp[500000];

int main(int argc, char const* argv[])
{
    int n;

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
    }

    merge_sort(ar, tmp, n);

    for (int i = 0; i < n - 1; i++) {
        printf("%d ", ar[i]);
    }
    printf("%d\n", ar[n-1]);
    printf("%d\n", count);

    return 0;
}

Compiler output:
a.cc: In instantiation of 'void m_sort(T*, T*, int, int) [with T = int]':
a.cc:28:11:   required from 'void merge_sort(T*, T*, int) [with T = int]'
   28 |     m_sort(ar, tmp, 0, n - 1);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:84:15:   required from here
   84 |     merge_sort(ar, tmp, n);
      |     ~~~~~~~~~~^~~~~~~~~~~~
a.cc:21:14: error: 'merge' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
   21 |         merge(ar, tmp, left, mid + 1, right);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:6: note: 'template<class T> void merge(T*, T*, int, int, int)' declared here, later in the translation unit
   32 | void merge(T ar[], T tmp[], int left, int mid, int right_last){
      |      ^~~~~
Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <type_traits>
#include <vector>

using namespace std;

static int comp_count = 0;


#ifdef _DEBUG
#include <stdio.h>
#include <stdarg.h>
    void _DbgFunc(char *fn, char *fmt, ...){
        va_list arg; va_start(arg, fmt);
        fprintf(stderr, "%s(", fn);
        vprintf(fmt, arg);
        fputs(")\n", stderr);
        va_end(arg);
    }
#endif

#define DbgP(fmt, ...) \
    do { if (_DEBUG) fprintf(stderr, fmt, __VA_ARGS__); } while (0)

#define DbgFunc(fmt, ...) \
    do { if (_DEBUG) _DbgFunc(__FUNCTION__, fmt, __VA_ARGS__); } while (0)

template<typename R, typename A>
void merge(int left, int left_last, int right_last, R ar, A tmp){
    int right = left_last + 1;
    int n = right_last - left + 1;
    int t = left;
    int c = left;
    DbgFunc("%d,%d,%d,%d", left, left_last, right, right_last);

    while (left <= left_last && right <= right_last) {
        if(ar[left] <= ar[right]){
            tmp[t] = ar[left];
            left++;
        }else{
            tmp[t] = ar[right];
            right++;
        }
        t++;
    }

    while (left <= left_last) {
        tmp[t++] = ar[left++];
    }
    while (right <= right_last) {
        tmp[t++] = ar[right++];
    }

    for (int i = 0; i < n; i++) {
        ar[right_last] = tmp[right_last];
        right_last--;
    }

    comp_count += t - c;
}

template<typename R, typename A>
void m_sort(int left, int right, R ar, A tmp){
    if(left < right){
        int mid = (left + right) / 2;
        
        m_sort(left, mid, ar, tmp);
        m_sort(mid + 1, right, ar, tmp);

        merge(left, mid, right, ar, tmp);
    }
}

template<typename T>
void merge_sort(T begin, T end){
    if(begin < end){
        int n = end - begin;
        using t = decay<decltype(*begin)>::type;
        auto tmp = new t[n];
        m_sort(0, end - begin - 1, begin, tmp);
    }
}

int ar[500000];

int main(int argc, char const* argv[])
{
    int n;

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
    }

    merge_sort(ar, ar + n);

    for (int i = 0; i < n - 1; i++) {
        printf("%d ", ar[i]);
    }
    printf("%d\n", ar[n - 1]);
    printf("%d\n", comp_count);

    return 0;
}

Compiler output:
a.cc: In function 'void merge(int, int, int, R, A)':
a.cc:28:14: error: '_DEBUG' was not declared in this scope
   28 |     do { if (_DEBUG) _DbgFunc(__FUNCTION__, fmt, __VA_ARGS__); } while (0)
      |              ^~~~~~
a.cc:36:5: note: in expansion of macro 'DbgFunc'
   36 |     DbgFunc("%d,%d,%d,%d", left, left_last, right, right_last);
      |     ^~~~~~~
a.cc: In function 'void merge_sort(T, T)':
a.cc:80:19: error: need 'typename' before 'std::decay<decltype (* begin)>::type' because 'std::decay<decltype (* begin)>' is a dependent scope
   80 |         using t = decay<decltype(*begin)>::type;
      |                   ^~~~~~~~~~~~~~~~~~~~~~~
      |                   typename 
a.cc:81:24: error: 't' does not name a type
   81 |         auto tmp = new t[n];
      |                        ^