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

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int merge(int A[],int n,int left,int mid,int right){
  int n1=mid-left
  int i,j;
  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;
  j=i=0;
  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 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(){
    nit 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<<end1;
    return 0;
}


Compiler output:
a.cc: In function 'int merge(int*, int, int, int, int)':
a.cc:11:3: error: expected ',' or ';' before 'int'
   11 |   int i,j;
      |   ^~~
a.cc:13:7: error: 'i' was not declared in this scope
   13 |   for(i=0;i<n1;i++)
      |       ^
a.cc:15:7: error: 'i' was not declared in this scope
   15 |   for(i=0;i<n2;i++)
      |       ^
a.cc:4:18: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000' to '-1863462912' [-Woverflow]
    4 | #define SENTINEL 200000000000
      |                  ^~~~~~~~~~~~
a.cc:17:15: note: in expansion of macro 'SENTINEL'
   17 |   L[n1]=R[n2]=SENTINEL;
      |               ^~~~~~~~
a.cc:18:3: error: 'j' was not declared in this scope
   18 |   j=i=0;
      |   ^
a.cc:18:5: error: 'i' was not declared in this scope
   18 |   j=i=0;
      |     ^
a.cc:28:1: warning: no return statement in function returning non-void [-Wreturn-type]
   28 | }
      | ^
a.cc: In function 'int main()':
a.cc:40:5: error: 'nit' was not declared in this scope; did you mean 'int'?
   40 |     nit A[MAX],n,i;
      |     ^~~
      |     int
a.cc:43:10: error: 'n' was not declared in this scope
   43 |     cin>>n;
      |          ^
a.cc:44:9: error: 'i' was not declared in this scope
   44 |     for(i=0;i<n;i++)
      |         ^
a.cc:45:13: error: 'a' was not declared in this scope
   45 |        cin>>a[i];
      |             ^
a.cc:47:15: error: 'A' was not declared in this scope
   47 |     mergeSort(A,n,0,n);
      |               ^
a.cc:49:9: error: 'i' was not declared in this scope
   49 |     for(i=0;i<n;i++){
      |         ^
a.cc:54:16: error: 'end1' was not declared in this scope
   54 |     cout<<cnt<<end1;
      |                ^~~~
Language: C++

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int 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 j=0,i=0;
  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 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(){
    nit 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<<end1;
    return 0;
}


Compiler output:
a.cc: In function 'int merge(int*, int, int, int, int)':
a.cc:11:3: error: expected ',' or ';' before 'int'
   11 |   int n2=right-mid;
      |   ^~~
a.cc:14:17: error: 'n2' was not declared in this scope; did you mean 'n1'?
   14 |   for(int i=0;i<n2;i++)
      |                 ^~
      |                 n1
a.cc:16:11: error: 'n2' was not declared in this scope; did you mean 'n1'?
   16 |   L[n1]=R[n2]=SENTINEL;
      |           ^~
      |           n1
a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
   27 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:5: error: 'nit' was not declared in this scope; did you mean 'int'?
   39 |     nit A[MAX],n,i;
      |     ^~~
      |     int
a.cc:42:10: error: 'n' was not declared in this scope
   42 |     cin>>n;
      |          ^
a.cc:43:9: error: 'i' was not declared in this scope
   43 |     for(i=0;i<n;i++)
      |         ^
a.cc:44:13: error: 'a' was not declared in this scope
   44 |        cin>>a[i];
      |             ^
a.cc:46:15: error: 'A' was not declared in this scope
   46 |     mergeSort(A,n,0,n);
      |               ^
a.cc:48:9: error: 'i' was not declared in this scope
   48 |     for(i=0;i<n;i++){
      |         ^
a.cc:53:16: error: 'end1' was not declared in this scope
   53 |     cout<<cnt<<end1;
      |                ^~~~
Language: C++

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int 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 j=0,i=0;
  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 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(){
    nit 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<<end1;
    return 0;
}


Compiler output:
a.cc: In function 'int merge(int*, int, int, int, int)':
a.cc:4:18: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000' to '-1863462912' [-Woverflow]
    4 | #define SENTINEL 200000000000
      |                  ^~~~~~~~~~~~
a.cc:16:15: note: in expansion of macro 'SENTINEL'
   16 |   L[n1]=R[n2]=SENTINEL;
      |               ^~~~~~~~
a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
   27 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:5: error: 'nit' was not declared in this scope; did you mean 'int'?
   39 |     nit A[MAX],n,i;
      |     ^~~
      |     int
a.cc:42:10: error: 'n' was not declared in this scope
   42 |     cin>>n;
      |          ^
a.cc:43:9: error: 'i' was not declared in this scope
   43 |     for(i=0;i<n;i++)
      |         ^
a.cc:44:13: error: 'a' was not declared in this scope
   44 |        cin>>a[i];
      |             ^
a.cc:46:15: error: 'A' was not declared in this scope
   46 |     mergeSort(A,n,0,n);
      |               ^
a.cc:48:9: error: 'i' was not declared in this scope
   48 |     for(i=0;i<n;i++){
      |         ^
a.cc:53:16: error: 'end1' was not declared in this scope
   53 |     cout<<cnt<<end1;
      |                ^~~~
Language: C++

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int 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 j=0,i=0;
  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 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(){
    nit 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<<end1;
    return 0;
}


Compiler output:
a.cc: In function 'int merge(int*, int, int, int, int)':
a.cc:4:18: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000' to '-1863462912' [-Woverflow]
    4 | #define SENTINEL 200000000000
      |                  ^~~~~~~~~~~~
a.cc:16:15: note: in expansion of macro 'SENTINEL'
   16 |   L[n1]=R[n2]=SENTINEL;
      |               ^~~~~~~~
a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
   27 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:5: error: 'nit' was not declared in this scope; did you mean 'int'?
   39 |     nit A[Max],n,i;
      |     ^~~
      |     int
a.cc:42:10: error: 'n' was not declared in this scope
   42 |     cin>>n;
      |          ^
a.cc:43:9: error: 'i' was not declared in this scope
   43 |     for(i=0;i<n;i++)
      |         ^
a.cc:44:13: error: 'a' was not declared in this scope
   44 |        cin>>a[i];
      |             ^
a.cc:46:15: error: 'A' was not declared in this scope
   46 |     mergeSort(A,n,0,n);
      |               ^
a.cc:48:9: error: 'i' was not declared in this scope
   48 |     for(i=0;i<n;i++){
      |         ^
a.cc:53:16: error: 'end1' was not declared in this scope
   53 |     cout<<cnt<<end1;
      |                ^~~~
Language: C++

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int 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 j=0,i=0;
  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 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<<end1;
    return 0;
}


Compiler output:
a.cc: In function 'int merge(int*, int, int, int, int)':
a.cc:4:18: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000' to '-1863462912' [-Woverflow]
    4 | #define SENTINEL 200000000000
      |                  ^~~~~~~~~~~~
a.cc:16:15: note: in expansion of macro 'SENTINEL'
   16 |   L[n1]=R[n2]=SENTINEL;
      |               ^~~~~~~~
a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
   27 | }
      | ^
a.cc: In function 'int main()':
a.cc:44:13: error: 'a' was not declared in this scope
   44 |        cin>>a[i];
      |             ^
a.cc:53:16: error: 'end1' was not declared in this scope
   53 |     cout<<cnt<<end1;
      |                ^~~~
Language: C++

#include<iostream>
using namespace std;
#define Max 500000
#define SENTINEL 200000000000

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

int 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 j=0,i=0;
  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 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 merge(int*, int, int, int, int)':
a.cc:4:18: warning: overflow in conversion from 'long int' to 'int' changes value from '200000000000' to '-1863462912' [-Woverflow]
    4 | #define SENTINEL 200000000000
      |                  ^~~~~~~~~~~~
a.cc:16:15: note: in expansion of macro 'SENTINEL'
   16 |   L[n1]=R[n2]=SENTINEL;
      |               ^~~~~~~~
a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
   27 | }
      | ^
a.cc: In function 'int main()':
a.cc:44:13: error: 'a' was not declared in this scope
   44 |        cin>>a[i];
      |             ^
Language: C++

#ALDS1_5-B Merge Sort
from collections import deque

def merge(A,B):
    ans = deque()
    count = 0
    while(True):
        if len(A)==0 and len(B) == 0:
            break
        elif len(A) == 0:
            ans.append(B.popleft())
        elif len(B) == 0:
            ans.append(A.popleft())
        elif A[0] > B[0]:
            ans.append(B.popleft())
        else:
            ans.append(A.popleft())
        count+=1
    return (ans.copy(),count)

n = int(input())
S = [int(i) for i in input().split()]
div = deque([S])
mer = deque()
count = 0
while(len(div)>0):
    d = div.pop()
    if(len(d)>2):
        mid = len(d)//2
        div.appendleft(d[:mid])
        div.appendleft(d[mid:])
    elif(len(d)==2):
        if d[0] > d[1]:
            mer.appendleft(d[::-1])
        else:
            mer.appendleft(d)
        count+=2
    else:
        mer.appendleft(d)
        
while(len(mer)>1):
    A = deque(mer.popleft())
    B = deque(mer.popleft())
    ret = merge(A,B)
    mer.append(ret[0])
    count+=ret[1]
    
ans = ""
for i in ret[0]:
    ans += str(i) + " "
print(ans[:-1])
print(count)


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #ALDS1_5
    1 | #ALDS1_5-B Merge Sort
      |  ^~~~~~~
a.cc:2:1: error: 'from' does not name a type
    2 | from collections import deque
      | ^~~~
Language: C++

#ALDS1_5-B Merge Sort
from collections import deque

def merge(A,B):
    ans = deque()
    count = 0
    while(True):
        if len(A)==0:
            if len(B)==0:
                break
            ans.append(B.popleft())
        elif len(B) == 0:
            ans.append(A.popleft())
        elif A[0] > B[0]:
            ans.append(B.popleft())
        else:
            ans.append(A.popleft())
        count+=1
    return (ans,count)

n = int(input())
S = [int(i) for i in input().split()]
div = deque([S])
mer = deque()
count = 0
while(len(div)>0):
    d = div.pop()
    if(len(d)>2):
        mid = len(d)//2
        div.appendleft(d[:mid])
        div.appendleft(d[mid:])
    elif(len(d)==2):
        if d[0] > d[1]:
            mer.appendleft(d[::-1])
        else:
            mer.appendleft(d)
        count+=2
    else:
        mer.appendleft(d)
        
while(len(mer)>1):
    A = deque(mer.popleft())
    B = deque(mer.popleft())
    ret = merge(A,B)
    mer.append(ret[0])
    count+=ret[1]
    
ans = ""
for i in ret[0]:
    ans += str(i) + " "
print(ans[:-1])
print(count)


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #ALDS1_5
    1 | #ALDS1_5-B Merge Sort
      |  ^~~~~~~
a.cc:2:1: error: 'from' does not name a type
    2 | from collections import deque
      | ^~~~
Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<int> v;
typedef v::iterator vi;
int c = 0;

void mm(vi l, vi m, vi r)
{
	v L(d(l, m));
	copy(l, m, L.begin());
	vi cp = L.begin();

	for (vi i = l; i != r; i++)
		if (cp == L.end())
			break;
		else if (m == r) {
			copy(cp, L.end(), i);
			break;
		} else if(*cp <= *m)
			*i = *cp, cp++;
		else
			*i = *m, m++;
}

void ms(vi l, vi r)
{
	if (l + 1 < r) {
		int d = r - l;
		vi m = l + d / 2;
		c += d;
		ms(l, m);
		ms(m, r);
		mm(l, m, r);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	v S(n);
	for (int &x :S)
		scanf("%d", &x);

	ms(S.begin(), S.end());

	for (int &x: S)
		printf("%s%d", &x == &S[0] ? "": " ", x);
	puts("");
	printf("%d\n", c);
}



Compiler output:
a.cc: In function 'void mm(vi, vi, vi)':
a.cc:12:13: error: 'd' was not declared in this scope
   12 |         v L(d(l, m));
      |             ^
Language: C++

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<cstdlib>
#include<string>
#define INF 0x3f3f3f3f
#define MAXM 5000 + 10
#define MAXN 500000 + 10

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int ans = 0;
int a[MAXN];

Merge(int a[], int left, int mid, int right)
{
    int n1 = mid - left, n2 = right - mid;
    int L[n1+5], R[n2+5];
    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] = INF, R[n2] = INF;
    int i = 0, j = 0;
    for(int k = left; k < right; k ++){
        if(L[i] <= R[j]) a[k] = L[i++];
        else a[k] = R[j++];
        ans ++;
    }
}
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; scanf("%d", &n);
    for(int i = 0; i < n; i ++) scanf("%d", &a[i]);

    MergeSort(a, 0, n);

    printf("%d\n", ans);
}

/*

The WAM is F**KING interesting .

*/



Compiler output:
a.cc:24:1: error: ISO C++ forbids declaration of 'Merge' with no type [-fpermissive]
   24 | Merge(int a[], int left, int mid, int right)
      | ^~~~~
a.cc: In function 'int Merge(int*, int, int, int)':
a.cc:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
   39 | }
      | ^
a.cc: At global scope:
a.cc:40:1: error: ISO C++ forbids declaration of 'MergeSort' with no type [-fpermissive]
   40 | MergeSort(int a[], int left, int right)
      | ^~~~~~~~~
a.cc: In function 'int MergeSort(int*, int, int)':
a.cc:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
Language: C++

#include <iostream>
using namespace std;

int cnt = 0;
void Merge(int a[], int left, int right, int middle){
  int i, j, h, buf[right-left+1];
  i = left;
  h = 0;
  j = middle + 1;
  while (i <= middle && j <= right){
    if (a[i] < a[j]){
      buf[h++] = a[i++];
      cnt++;
    }
    else{
      buf[h++] = a[j++];
      cnt++;
    }
  }
  while (i <= middle){
    buf[h++] = a[i++];
    cnt++;
  }

  while (j <= right){
    buf[h++] = a[j++];
    cnt++;
  }

  for (i = left; i <= right; i++)
    a[i] = buf[i-left];
  
}
void MergeSort(int a[], int l, int r){
    int mid;
    if (l < r)
    {
      mid=(l+r)/2;
  
      MergeSort(a, l, mid);
      MergeSort(a, mid+1, r);
 
      Merge(a, l, r, mid);
    }
}
 
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  MergeSort(a, 0, n-1);
  
  for (int j = 0; j < n; j++)
    if(j == n-1){
      cout << a[j];
    }
    cout<<a[j]<<" ";

  cout << endl<<cnt<<endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:60:13: error: 'j' was not declared in this scope
   60 |     cout<<a[j]<<" ";
      |             ^
Language: C++

/* 7.1 マージソート ALDS1_5_B: Merge Sort
n個の整数を含む数列Sを上の疑似コードに従ったマージソートで昇順に整列するプログラムを作成してください。また、mergeにおける比較回数の総数を報告してください。
コンパイル g++ -o alds1_5_b.exe alds1_5_b.cpp -Wall

入力 1行目にn、2行目にSを表すn個の整数が与えられます
出力 1行目に整列済の数列Sを出力してください。数列の隣り合う要素は1つの空白で区切ってください。2行目に比較回数を出力してください。
制約 n<=500,000 , 0<=Sの要素<=10^9

実行 alds1_5_b.exe
入力例
  10
  8 5 9 2 6 3 7 1 10 4
出力例
  1 2 3 4 5 6 7 8 9 10
  34
*/

#include <iostream>
/* C++のstdio.hみたいなもの、cin (scanf), cout (printf) のためにincludeします。 */
using namespace std;
/* 名前空間にstdを指定する。毎回、std::cin , std::cout と記述するのはうっとおしいので省略するため。*/

#define MAX 500000
#define SENTINEL 2000000000 // 番兵

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

void merge(int A[],int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
// C++forループ専用のint型を宣言できる
// ループの中のみ有効なので安全
  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 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(void) {
  int A[MAX], n, i;
  cnt = 0;

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

  mergeSort(A, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
  	cout << A[i]; // printf("%d",A[i]);
  }
  cout << endl; // endlは改行

  cout << cnt << endl; // printf("\n");



Compiler output:
a.cc: In function 'int main()':
a.cc:71:23: error: expected '}' at end of input
   71 |   cout << cnt << endl; // printf("\n");
      |                       ^
a.cc:57:16: note: to match this '{'
   57 | int main(void) {
      |                ^
Language: C++

cnt = 0
def merge(A, left, mid, right):
  global cnt
  #print("marge ",A,left,mid,right)
  n1 = mid - left
  n2 = right - mid
  #L = [0] * (n1+1)
  #R = [0] * (n2+1)
  L = [0] * (n1+1)
  R = [0] * (n2+1)
  
  for i in range(int(n1)):
    L[i] = A[left + i]
  for i in range(int(n2)):
    R[i] = A[mid + i]
  L[n1] = 999999999
  R[n2] = 999999999
  i = 0
  j = 0
  for k in range(left,right):
    cnt+=1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1

def mergeSort(A, left, right):
  #print("margeSort ",A,left,right)
  if left+1 < right:
    mid = int((left + right)/2)
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

n = int(input())
S = list(map(int,input().split()))
mergeSort(S, 0, n)
S = map(str, S)
print(' '.join(S))
print(cnt)


Compiler output:
a.cc:4:4: error: invalid preprocessing directive #print
    4 |   #print("marge ",A,left,mid,right)
      |    ^~~~~
a.cc:7:4: error: invalid preprocessing directive #L
    7 |   #L = [0] * (n1+1)
      |    ^
a.cc:8:4: error: invalid preprocessing directive #R
    8 |   #R = [0] * (n2+1)
      |    ^
a.cc:30:4: error: invalid preprocessing directive #print
   30 |   #print("margeSort ",A,left,right)
      |    ^~~~~
a.cc:1:1: error: 'cnt' does not name a type; did you mean 'int'?
    1 | cnt = 0
      | ^~~
      | int
Language: C++

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

int LEFT[MAX/2+2],RIGHT[MAX/2+2];
int count;

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++){
		LEFT[i]=A[left+i];
	}
	for(i=0; i<n2; i++){
		RIGHT[i]=A[mid+i];
	}
	
	LEFT[n1]=RIGHT[n2]=data;
	int i=0;j=0;//新たにカウント用変数を宣言する
	int k;
	for(k=left; k<right; k++){
		count++;
		if(LEFT[i]<=RIGHT[j]){
			A[k]=LEFT[i++];
		}
		
		else{
			A[k]=RIGHT[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;
	count=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<<" ";//iが非ゼロであれば空白を、そうでなければA[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:13:13: error: 'i' was not declared in this scope
   13 |         for(i=0; i<n1; i++){
      |             ^
a.cc:16:13: error: 'i' was not declared in this scope
   16 |         for(i=0; i<n2; i++){
      |             ^
a.cc:21:17: error: 'j' was not declared in this scope
   21 |         int i=0;j=0;//新たにカウント用変数を宣言する
      |                 ^
a.cc: In function 'int main()':
a.cc:45:18: error: expected ']' before '}' token
   45 |         int A[MAX},n,i;
      |                  ^
a.cc: At global scope:
a.cc:45:19: error: mixing declarations and function-definitions is forbidden
   45 |         int A[MAX},n,i;
      |                   ^
a.cc:46:9: error: 'count' does not name a type
   46 |         count=0;
      |         ^~~~~
a.cc:48:9: error: 'cin' does not name a type
   48 |         cin>>n;
      |         ^~~
a.cc:49:9: error: expected unqualified-id before 'for'
   49 |         for(i=0; i<n; i++)
      |         ^~~
a.cc:49:18: error: 'i' does not name a type
   49 |         for(i=0; i<n; i++)
      |                  ^
a.cc:49:23: error: 'i' does not name a type
   49 |         for(i=0; i<n; i++)
      |                       ^
a.cc:52:18: error: expected constructor, destructor, or type conversion before '(' token
   52 |         mergesort(A,n,0,n);
      |                  ^
a.cc:54:9: error: expected unqualified-id before 'for'
   54 |         for(i=0; i<n; i++){
      |         ^~~
a.cc:54:18: error: 'i' does not name a type
   54 |         for(i=0; i<n; i++){
      |                  ^
a.cc:54:23: error: 'i' does not name a type
   54 |         for(i=0; i<n; i++){
      |                       ^
a.cc:58:9: error: 'cout' does not name a type
   58 |         cout<<endl;
      |         ^~~~
a.cc:60:9: error: 'cout' does not name a type
   60 |         cout<<cnt<<endl;
      |         ^~~~
a.cc:62:9: error: expected unqualified-id before 'return'
   62 |         return 0;
      |         ^~~~~~
a.cc:63:9: error: expected declaration before '}' token
   63 |         }
      |         ^
Language: C++

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

int LEFT[MAX/2+2],RIGHT[MAX/2+2];
int count;

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++){
		LEFT[i]=A[left+i];
	}
	for(i=0; i<n2; i++){
		RIGHT[i]=A[mid+i];
	}
	
	LEFT[n1]=RIGHT[n2]=data;
	int i=0;j=0;//新たにカウント用変数を宣言する
	int k;
	for(k=left; k<right; k++){
		count++;
		if(LEFT[i]<=RIGHT[j]){
			A[k]=LEFT[i++];
		}
		
		else{
			A[k]=RIGHT[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;
	count=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<<" ";//iが非ゼロであれば空白を、そうでなければA[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:13:13: error: 'i' was not declared in this scope
   13 |         for(i=0; i<n1; i++){
      |             ^
a.cc:16:13: error: 'i' was not declared in this scope
   16 |         for(i=0; i<n2; i++){
      |             ^
a.cc:21:17: error: 'j' was not declared in this scope
   21 |         int i=0;j=0;//新たにカウント用変数を宣言する
      |                 ^
a.cc: In function 'int main()':
a.cc:60:15: error: 'cnt' was not declared in this scope; did you mean 'int'?
   60 |         cout<<cnt<<endl;
      |               ^~~
      |               int
Language: C++

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

int LEFT[MAX/2+2],RIGHT[MAX/2+2];
int count;

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++){
		LEFT[i]=A[left+i];
	}
	for(i=0; i<n2; i++){
		RIGHT[i]=A[mid+i];
	}
	
	LEFT[n1]=RIGHT[n2]=data;
	int i=0,j=0;//新たにカウント用変数を宣言する
	int k;
	for(k=left; k<right; k++){
		count++;
		if(LEFT[i]<=RIGHT[j]){
			A[k]=LEFT[i++];
		}
		
		else{
			A[k]=RIGHT[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;
	count=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<<" ";//iが非ゼロであれば空白を、そうでなければA[i]をcoutする。
		cout<<A[i];
	}
	cout<<endl;
	
	cout<<count<<endl;
	
	return 0;
	}


Compiler output:
a.cc: In function 'void merge(int*, int, int, int, int)':
a.cc:13:13: error: 'i' was not declared in this scope
   13 |         for(i=0; i<n1; i++){
      |             ^
a.cc:16:13: error: 'i' was not declared in this scope
   16 |         for(i=0; i<n2; i++){
      |             ^
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 le[]ft,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int i;
	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;
	int k;
	for(k=left;k<right;k++){
		cnt++;
		if(L[i]<=R[i]){
			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(1) cout << " ";
			cout << A[i];
		}
		cout << end1;

		cout << cnt << end1;

		return 0;
}
	



Compiler output:
a.cc:9:34: error: expected ',' or '...' before 'ft'
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |                                  ^~
a.cc: In function 'void merge(int*, int, int*)':
a.cc:10:18: error: 'mid' was not declared in this scope
   10 |         int n1 = mid - left;
      |                  ^~~
a.cc:14:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   14 |                 L[i] = A[left + i];
      |                          ~~~~~^~~
a.cc:14:25: error: invalid types 'int*[std::ios_base& (*)(std::ios_base&)]' for array subscript
   14 |                 L[i] = A[left + i];
      |                         ^
a.cc:21:13: error: redeclaration of 'int i'
   21 |         int i=0,j=0;
      |             ^
a.cc:12:13: note: 'int i' previously declared here
   12 |         int i;
      |             ^
a.cc:23:15: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |               ^~~~
      |               |
      |               std::ios_base& (*)(std::ios_base&)
a.cc:23:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |                    ~^~~~~~
a.cc: In function 'void mergeSort(int*, int, int, int)':
a.cc:38:27: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   38 |                 merge(A,n,left,mid,right);
      |                           ^~~~
      |                           |
      |                           int
a.cc:38:22: error: too many arguments to function 'void merge(int*, int, int*)'
   38 |                 merge(A,n,left,mid,right);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:9:6: note: declared here
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |      ^~~~~
a.cc: In function 'int main()':
a.cc:51:25: error: 'end1' was not declared in this scope
   51 |                 cout << end1;
      |                         ^~~~
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 le[]ft,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int i;
	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;
	int k;
	for(k=left;k<right;k++){
		cnt++;
		if(L[i]<=R[i]){
			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(1) cout << " ";
			cout << A[i];
		}
		cout << endl;

		cout << cnt << endl;

		return 0;
}
	



Compiler output:
a.cc:9:34: error: expected ',' or '...' before 'ft'
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |                                  ^~
a.cc: In function 'void merge(int*, int, int*)':
a.cc:10:18: error: 'mid' was not declared in this scope
   10 |         int n1 = mid - left;
      |                  ^~~
a.cc:14:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   14 |                 L[i] = A[left + i];
      |                          ~~~~~^~~
a.cc:14:25: error: invalid types 'int*[std::ios_base& (*)(std::ios_base&)]' for array subscript
   14 |                 L[i] = A[left + i];
      |                         ^
a.cc:21:13: error: redeclaration of 'int i'
   21 |         int i=0,j=0;
      |             ^
a.cc:12:13: note: 'int i' previously declared here
   12 |         int i;
      |             ^
a.cc:23:15: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |               ^~~~
      |               |
      |               std::ios_base& (*)(std::ios_base&)
a.cc:23:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |                    ~^~~~~~
a.cc: In function 'void mergeSort(int*, int, int, int)':
a.cc:38:27: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   38 |                 merge(A,n,left,mid,right);
      |                           ^~~~
      |                           |
      |                           int
a.cc:38:22: error: too many arguments to function 'void merge(int*, int, int*)'
   38 |                 merge(A,n,left,mid,right);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:9:6: note: declared here
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |      ^~~~~
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 le[]ft,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int i;
	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;
	int k;
	for(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(1) cout << " ";
			cout << A[i];
		}
		cout << endl;

		cout << cnt << endl;

		return 0;
}
	



Compiler output:
a.cc:9:34: error: expected ',' or '...' before 'ft'
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |                                  ^~
a.cc: In function 'void merge(int*, int, int*)':
a.cc:10:18: error: 'mid' was not declared in this scope
   10 |         int n1 = mid - left;
      |                  ^~~
a.cc:14:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   14 |                 L[i] = A[left + i];
      |                          ~~~~~^~~
a.cc:14:25: error: invalid types 'int*[std::ios_base& (*)(std::ios_base&)]' for array subscript
   14 |                 L[i] = A[left + i];
      |                         ^
a.cc:21:13: error: redeclaration of 'int i'
   21 |         int i=0,j=0;
      |             ^
a.cc:12:13: note: 'int i' previously declared here
   12 |         int i;
      |             ^
a.cc:23:15: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |               ^~~~
      |               |
      |               std::ios_base& (*)(std::ios_base&)
a.cc:23:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   23 |         for(k=left;k<right;k++){
      |                    ~^~~~~~
a.cc: In function 'void mergeSort(int*, int, int, int)':
a.cc:38:27: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   38 |                 merge(A,n,left,mid,right);
      |                           ^~~~
      |                           |
      |                           int
a.cc:38:22: error: too many arguments to function 'void merge(int*, int, int*)'
   38 |                 merge(A,n,left,mid,right);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:9:6: note: declared here
    9 | void merge(int A[],int n,int le[]ft,int mid,int right){
      |      ^~~~~
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;
	int i;
	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;
	int k;
	for(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(1) 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:21:13: error: redeclaration of 'int i'
   21 |         int i=0,j=0;
      |             ^
a.cc:12:13: note: 'int i' previously declared here
   12 |         int i;
      |             ^
Language: C++

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

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:40:37: error: expected ';' before 'mergeSort'
   40 |     for(i = 0; i<n; i++) cin >> A[i]
      |                                     ^
      |                                     ;
   41 |     mergeSort(A, n, 0, n);
      |     ~~~~~~~~~
Language: C++

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

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:40:37: error: expected ';' before 'mergeSort'
   40 |     for(i = 0; i<n; i++) cin >> A[i]
      |                                     ^
      |                                     ;
   41 |     mergeSort(A, n, 0, n);
      |     ~~~~~~~~~
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++) 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:40:37: error: expected ';' before 'mergeSort'
   40 |     for(i = 0; i<n; i++) cin >> A[i]
      |                                     ^
      |                                     ;
   41 |     mergeSort(A, n, 0, n);
      |     ~~~~~~~~~
Language: C++

#include <iostream>
#define LEN 100005

using namespace std;

typedef struct{
  char name[100];
  int t;
}P;

int main(){
  P Q[L+1];
  int n, q, i;
  int sum;
  cin >> n >> q;
  for(i=1;i<=n;++i)
    cin >> Q[i].name >> Q[i].t;

  for(i=1;i<=n;++i){
    if(Q[i] > q)Q[i] -= q;
    else{
      q[i] = 0;
    }
  }
  
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:12:7: error: 'L' was not declared in this scope
   12 |   P Q[L+1];
      |       ^
a.cc:17:12: error: 'Q' was not declared in this scope
   17 |     cin >> Q[i].name >> Q[i].t;
      |            ^
a.cc:20:8: error: 'Q' was not declared in this scope
   20 |     if(Q[i] > q)Q[i] -= q;
      |        ^
a.cc:22:8: error: invalid types 'int[int]' for array subscript
   22 |       q[i] = 0;
      |        ^
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(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:8:6: error: expected unqualified-id before 'int'
    8 | void(int A[], int n, int left, int mid, int right){
      |      ^~~
a.cc:8:6: error: expected ')' before 'int'
    8 | void(int A[], int n, int left, int mid, int right){
      |     ~^~~
      |      )
a.cc: In function 'void mergeSort(int*, int, int, int)':
a.cc:31:9: error: 'merge' was not declared in this scope
   31 |         merge(A,n,left,mid,right);
      |         ^~~~~
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:41:14: error: 'cout' was not declared in this scope
   41 |         if(i)cout<<" ";
      |              ^~~~
a.cc:41:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:42:9: error: 'cout' was not declared in this scope
   42 |         cout<<A[i];
      |         ^~~~
a.cc:42:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:5: error: 'cout' was not declared in this scope
   44 |     cout<<endl;
      |     ^~~~
a.cc:44:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:11: error: 'endl' was not declared in this scope
   44 |     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(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:41:14: error: 'cout' was not declared in this scope
   41 |         if(i)cout<<" ";
      |              ^~~~
a.cc:41:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:42:9: error: 'cout' was not declared in this scope
   42 |         cout<<A[i];
      |         ^~~~
a.cc:42:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:5: error: 'cout' was not declared in this scope
   44 |     cout<<endl;
      |     ^~~~
a.cc:44:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:11: error: 'endl' was not declared in this scope
   44 |     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;