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

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using int_vec = vector<long>;

void print(const int_vec& v) {
    int_vec::const_iterator it;
    for (it = v.begin(); it != v.end()-1; ++it) {
        cout << *it << " ";
    }
    cout << *it << endl;
}


int insertion_sort(int_vec& v, int g) {
    int count = 0;
    for (int i = g; i < v.size(); ++i) {
        auto x = v[i];
        int j = i - g;
        for (; j >= 0 && v[j] > x; j -= g) {
            v[j+g] = v[j];
            ++count;
        }
        v[j+g] = x;
    }
    return count;
}

int shell_sort(int_vec& v) {
    // int m = min(static_cast<int>((v.size() - 1) / 3) + 1, 100);
    int_vec G;
    for (int i = 1; i <q v.size(); i = i * 3 + 1) {
        G.push_back(i);
    }
    reverse(G.begin(), G.end());
    cout << G.size() << endl;
    if (G.size() > 0)
        print(G);

    int count = 0;
    for (auto it = G.begin(); it != G.end(); ++it) {
        count += insertion_sort(v, *it);
    }
    return count;
}

int main() {
    int n;
    cin >> n;

    int_vec v;
    for (int i = 0; i < n; ++i) {
        long x;
        cin >> x;
        v.push_back(x);
    }

    auto c = shell_sort(v);
    cout << c << endl;
    for (auto it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int shell_sort(int_vec&)':
a.cc:34:24: error: 'q' was not declared in this scope
   34 |     for (int i = 1; i <q v.size(); i = i * 3 + 1) {
      |                        ^
a.cc:34:25: error: expected ';' before 'v'
   34 |     for (int i = 1; i <q v.size(); i = i * 3 + 1) {
      |                         ^~
      |                         ;
a.cc:34:32: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = long int; _Alloc = std::allocator<long int>; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   34 |     for (int i = 1; i <q v.size(); i = i * 3 + 1) {
      |                          ~~~~~~^~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:992:7: note: declared here
  992 |       size() const _GLIBCXX_NOEXCEPT
      |       ^~~~
a.cc:34:34: error: expected ')' before ';' token
   34 |     for (int i = 1; i <q v.size(); i = i * 3 + 1) {
      |         ~                        ^
      |                                  )
a.cc:34:36: error: 'i' was not declared in this scope
   34 |     for (int i = 1; i <q v.size(); i = i * 3 + 1) {
      |                                    ^
Language: C++

include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <stack>
using namespace std;

//#define DEBUG (1)

#ifdef DEBUG
#define DPRINT(...)  printf("D(L%d) %s: ", __LINE__, __func__); printf(__VA_ARGS__)
#else
#define DPRINT(...)
#endif

void  getGarray(int arraySize, int *&pG, int &gSize);
void  insertionSort(int array[], const int arraySize, const int d);
void printArray(const int array[], const int arraySize);

int g_cnt = 0;

int main() {
	int arraySize;
	cin >> arraySize; cin.ignore();
	assert(arraySize > 0);

	int array[arraySize];
	for (int i = 0; i < arraySize; i++)
		cin >> array[i];

	// shell sort
	int *pG, gSize;
	getGarray(arraySize, pG, gSize);

	cout << gSize << endl;
	printArray(pG, gSize);

	for (int i = 0; i < gSize; i++)
		insertionSort(array, arraySize, pG[i]);

	cout << g_cnt << endl;
	for (int i = 0; i < arraySize; i++)
		cout << array[i] << endl;

	delete [] pG;
	return 0;
}

void getGarray(int arraySize, int *&pG, int &gSize) {
	int i = 1;
	stack<int> s;
	while (i <= arraySize) {
		s.push(i);
		i *= 2;
	}
	gSize = s.size();
	pG = new int[gSize];
	for (int i = 0; i < gSize; i++) {
		pG[i] = s.top();
		s.pop();
	}
#ifdef DEBUG
	DPRINT("gSize: %d\n", gSize);
	DPRINT("pG addr %p\n", pG);
	DPRINT("pG array: ");
	printArray(pG, gSize);
#endif
}

void insertionSort(int array[], const int arraySize, const int d) {
	for (int i = d; i < arraySize; i += d){
		int j = i;
		int v = array[j];
		while (j > 0 && array[j] < array[j-d]) {
			array[j] = array[j-d];
			j -= d;
			g_cnt++;
		}
		array[j] = v;
	}
#ifdef DEBUG
	DPRINT("array: ");
	printArray(array, arraySize);
#endif
	return ;
}

void printArray(const int array[], const int arraySize) {
	for (int i = 0; i < arraySize; i++) {
		if (i > 0)	cout << " ";
		cout << array[i];
	}
	cout << endl;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <stdio.h>
      | ^~~~~~~
In file included from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/x86_64-linux-gnu/sys/types.h:33:9: error: '__u_char' does not name a type; did you mean '__u_short'?
   33 | typedef __u_char u_char;
      |         ^~~~~~~~
      |         __u_short
Language: C++

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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n; i+) {
    int v = A[i];0; i-- ) {
  
    int j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(int A[], int n){
  // 数列G = {1, 4, 13, 40, 121, 364, 1093, ..}を生成
  for ( int h = 1; ; ) {
    if ( h > n ) break;
    G.push_back(h);
    h = 3*h + 1;
  }

  for ( int i = G.size()-1; i >= 0; i-- ){
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);

  cout << G.size() << endl;
  for ( int i = G.size() - 1; i >= 0; i-- ){
    printf("%d", G[i]);
    if( i ) printf(" ");
  }
  printf("\n");
  printf("%d]n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:16:29: error: expected primary-expression before ')' token
   16 |   for ( int i = g; i < n; i+) {
      |                             ^
a.cc:17:24: error: expected ';' before ')' token
   17 |     int v = A[i];0; i-- ) {
      |                        ^~
      |                        ;
a.cc:29:31: error: a function-definition is not allowed here before '{' token
   29 | void shellSort(int A[], int n){
      |                               ^
a.cc:42:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   42 | int main() {
      |         ^~
a.cc:42:9: note: remove parentheses to default-initialize a variable
   42 | int main() {
      |         ^~
      |         --
a.cc:42:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:42:12: error: a function-definition is not allowed here before '{' token
   42 | int main() {
      |            ^
a.cc:59:2: error: expected '}' at end of input
   59 | }
      |  ^
a.cc:15:42: note: to match this '{'
   15 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
 
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
 
//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n; i+) {
    int v = A[i];
    int j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}
 
void shellSort(int A[], int n){
  // 数列G = {1, 4, 13, 40, 121, 364, 1093, ..}を生成
  for ( int h = 1; ; ) {
    if ( h > n ) break;
    G.push_back(h);
    h = 3*h + 1;
  }
 
  for ( int i = G.size()-1; i >= 0; i-- ){
    insertionSort(A, n, G[i]);
  }
}
 
int main() {
  cin >> n;
  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
  cnt = 0;
 
  shellSort(A, n);
 
  cout << G.size() << endl;
  for ( int i = G.size() - 1; i >= 0; i-- ){
    printf("%d", G[i]);
    if( i ) printf(" ");
  }
  printf("\n");
  printf("%d]n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);
 
  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:16:29: error: expected primary-expression before ')' token
   16 |   for ( int i = g; i < n; i+) {
      |                             ^
Language: C++

#include<stdio.h>
#include<algorithm>
#include<vector>
#include <iostream>
using namespace std;

long long time;
vector<int> G;
int A[1000000];

void insertionSort(int A[],int n,int x)
{
    int t;
    for(int i=0; i<x; i++)
    {

        for(int j=i+x; j<n; j=j+x)
        {
            int k=j;
            while(k-x>=0&&A[k]<A[k-x])
            {
                t=A[k];
                A[k]=A[k-x];
                A[k-x]=t;
                k=k-x;
                time++;
            }
        }

    }
}
void shellSort(int A[],int n)
{

    for(int h=1; h<=n; h=3*h+1)
    {
        G.push_back(h);
    }
    for(int i=G.size()-1; i>=0; i--)
    {
        insertionSort(A,n,G[i]);
    }
}

void print(int A[],int n)
{
    for(int i=0; i<n; i++)
        cout<<A[i]<<endl;
}



int main()
{
    time=0;
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>A[i];
    shellSort(A,n);

    cout<<G.size()<<endl;
    for(int i=G.size()-1; i>0; i--)
        cout<<G[i]<<" ";
    cout<<G[0]<<endl;
    cout<<time<<endl;
    print(A,n);
    return 0;

}



Compiler output:
a.cc:7:11: error: 'long long int time' redeclared as different kind of entity
    7 | long long time;
      |           ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:26:17: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   26 |                 time++;
      |                 ^~~~
a.cc:26:21: error: lvalue required as increment operand
   26 |                 time++;
      |                     ^~
a.cc: In function 'int main()':
a.cc:55:9: error: assignment of function 'time_t time(time_t*)'
   55 |     time=0;
      |     ~~~~^~
Language: C++

import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [int((3**i-1)/2)for i in range(30,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.15**i-1)/1.15)for i in range(18,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

#include <iostream>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

static void printArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
}

static void inputArray(int A[], int N) {
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
}

static int insersionSort(int A[], int N, int g) {
  int v, j, count = 0;
  for (int i = g; i < N; i++) {
    v = A[i];
    j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j = j - g;
      count++;
    }
    A[j + g] = v;
  }
  return count;
}

#include <cstdio>

static int shellSort(array<int, 1000000>& A,  int N) {
  array<int, 1000000> sortArray(A);
  int g, startedIndex = 0, count = 0;
  vector<int> G;
  for (int g = 1; g < N; ;) {
    G.push_back(g);
    g = 3 * g;
  }
  for (g = G.size() - 1;  g >= 0; g--) {
    if (G[g] * 2 > N) {
      continue;
    }
    if (startedIndex == 0) {
      startedIndex = g;
    }
    count += insersionSort(sortArray.data(), N, G[g]);
     if (count > pow(N, 1.5f)) {
      sortArray = A;
      continue;
    } 
  }

  cout << startedIndex + 1 << endl;
  for (int i = startedIndex; i >= 0; i--) {
    cout << G[i];
    cout << ' ';
  }
  cout << endl;
  cout << count << endl;
  A = sortArray;
  return count;
}
  
int main() {
  int N;
  cin >> N;

  array<int, 1000000> A;
  inputArray(A.data(), N);

//  printArray(A.data(), N);

  shellSort(A, N);

  printArray(A.data(), N);
  
  return 0;
}



Compiler output:
a.cc: In function 'int shellSort(std::array<int, 1000000>&, int)':
a.cc:41:26: error: expected primary-expression before ';' token
   41 |   for (int g = 1; g < N; ;) {
      |                          ^
a.cc:41:25: error: expected ')' before ';' token
   41 |   for (int g = 1; g < N; ;) {
      |       ~                 ^~
      |                         )
a.cc:41:27: error: expected primary-expression before ')' token
   41 |   for (int g = 1; g < N; ;) {
      |                           ^
Language: C++

#include <stdio.h>
#include <stdlib.h>

int cnt = 0;
size_t gaps[] = { 1, 4, 9, 20, 46, 103 };
static const size_t len_gaps = sizeof(gaps) / sizeof(*gaps);

void insertion_sort(int* array, size_t size, size_t gap)
{
  for(size_t i = gap; i < size; i++) {
    int max = array[i];
    int k = i - gap;
    while(0 <= k && max < array[k]) {
      array[k + gap] = array[k];
      k = k - gap;
      cnt++;
    }
    array[k + gap] = max;
  }
}

void shell_sort(int* array, size_t size)
{
  size_t gap_index;
  for(gap_index = 0; gap_index < len_gaps; gap_index++) {
    if(size / 2 < gaps[gap_index]) {
      break;
    }
  }
  gap_index--;
  printf("%lu\n", gap_index+1);
  for(int i = (int)gap_index; 0 <= i; i--) {
    printf("%lu", gaps[i]);
    if(i == 0) {
      putchar('\n');
    } else {
      putchar(' ');
    }
    insertion_sort(array, size, gaps[i]);
  }
}

int main()
{
  int size;
  scanf("%d", &size);
  int* array = malloc(sizeof(int) * size);
  if(!array) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  for(int i = 0; i < size; i++) {
    scanf("%d", &array[i]);
  }
  shell_sort(array, size);
  printf("%d\n", cnt);
  for(int i = 0; i < size; i++) {
    printf("%d\n", array[i]);
  }

  free(array);
  return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:47:22: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   47 |   int* array = malloc(sizeof(int) * size);
      |                ~~~~~~^~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      void*
Language: C++

#include <iostream>
using namespace std;

int insertionSort(int A[], int n, int g)
{
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

int main() {
	int A[1000000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)	
		cin >> A[i];

	int cnt = 0;
	int m = 0;
	int nn = n;
	int G[100];

	while (nn > 0){
		m++;
		nn = nn/2;
	}

	for (int i = 0; i < m; i++)
	{
		G[i] = pow(2, m - i - 1);
		cnt += insertionSort(A, n, G[i]);
	}

	cout << m << endl;
	for (int i = 0; i < m; i++)
		cout << G[i] << " ";
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << A[i] << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:24: error: 'pow' was not declared in this scope
   39 |                 G[i] = pow(2, m - i - 1);
      |                        ^~~
Language: C++

#include <iostream>
using namespace std;

int insertionSort(int A[], int n, int g)
{
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

int main() {
	int A[1000000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)	
		cin >> A[i];

	int cnt = 0;
	int m = 0;
	int nn = n;
	int G[100];

	while (nn > 0){
		m++;
		nn = nn/2;
	}

	for (int i = 0; i < m; i++)
	{
		G[i] = std::pow(2, m - i - 1);
		cnt += insertionSort(A, n, G[i]);
	}

	cout << m << endl;
	for (int i = 0; i < m; i++)
		cout << G[i] << " ";
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << A[i] << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:39:29: error: 'pow' is not a member of 'std'
   39 |                 G[i] = std::pow(2, m - i - 1);
      |                             ^~~
Language: C++

#include <stdio.h>
#include <iostream>

int cnt = 0;
void print(int N, int *A) 
{

	for (int i = 0; i < N; i++)
	{
		cout << A[i];
		if (i == N - 1) 
		{
			//do nothing
		}
		else
		{
			cout << endl;
		}
	}
}


void inserSort(int N, int *A,int B)
{
	int v;
	int j;

	for (int i = B; i < N; i++)
	{
		v = A[i];
		j = i - B;

		while (j >= 0 && A[j] > v)
		{
			A[j + B] = A[j];
			j = j - B;
			cnt++;
		}

		A[j+B] = v;
	}
}

void shellSort(int N,int *A) 
{
	int j = 0,i=0, h=0, B[10000];

	while (true)
	{
		B[i] = 3 * h + 1;
		h = B[i];
		if ((3 * h + 1) > N) 
		{
			break;
		}
		i++;
	}
	cout << (i+1) << endl;
	for (int j = i; j >= 0; j--)
	{
		printf("%d", B[j]);
		inserSort(N,A,B[j]);
		if (j != 0) 
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}
	printf("%d", cnt);
	cout << endl;
	print(N, A);

}

int main()
{
	int N, A[10000],i=0;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	shellSort(N, A);

	return 0;
}



Compiler output:
a.cc: In function 'void print(int, int*)':
a.cc:10:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   10 |                 cout << A[i];
      |                 ^~~~
      |                 std::cout
In file included from a.cc:2:
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:17:33: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   17 |                         cout << endl;
      |                                 ^~~~
      |                                 std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: In function 'void shellSort(int, int*)':
a.cc:58:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   58 |         cout << (i+1) << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:58:26: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   58 |         cout << (i+1) << endl;
      |                          ^~~~
      |                          std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: In function 'int main()':
a.cc:82:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   82 |         cin >> N;
      |         ^~~
      |         std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>

long long cnt=0;

int* insertionSort(int* A, int N, int g){
  int tmp;

  for(int i=g; i<N; i++){
    tmp = A[i];
    int j = i-g;
    while (j>=0 && A[j]>tmp) {
      A[j+g]=A[j];
      j = j - g;
      cnt++;
    }
    A[j+g]=tmp;
  }
  return A;
}

void shellSort(int* A, int n){
  std::vector<int> G;
  for (int i = 0; i < n; i = 3i+1) {
    G.push_back(i);
  }
  int m =  G.size();
  std::cout << m << '\n';
  for (int i = m-1; i >=0; i--) {
    std::cout << G[i];
    if (i!=m-1) {
      std::cout << " ";
    }else{
      std::cout << '\n';
    }
  }

  for (int i = m-1; i >=0; i--) {
    A = insertionSort(A,n,G[i]);
  }

  std::cout << cnt << '\n';

  for (size_t i = 0; i < n; i++) {
    std::cout << A[i] << '\n';
  }
}

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

  shellSort(A, n);

  return 0;
}



Compiler output:
a.cc: In function 'void shellSort(int*, int)':
a.cc:25:32: error: cannot convert '__complex__ int' to 'int' in assignment
   25 |   for (int i = 0; i < n; i = 3i+1) {
Language: C++

#include<iostream>
using namespace std;
__int64 cnt = 0;
int G[20], m = 0;
int num[1000000];
void insertSort(int *arr, int n, int g) {
    for(int i = g; i < n; i++) {
        int v = arr[i];
        int j = i - g;
        while(j >= 0 && arr[j] > v) {
            arr[j + g] = arr[j];
            j -= g;
            cnt++;
        }
        arr[j + g] = v;
    }
}

void shellSort(int *arr, int N) {
    for(int temp = 1, i = 0; temp < N; m++,i++) {
        G[i] = temp;
        temp *= 3;
        temp += 1;
    }
    for(int i = 0; i < m; i++) {
        insertSort(arr, N, G[m - i - 1]);
    }
}
int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> num[i];
    }
    shellSort(num, N);
    cout << m <<endl;
    for(int i = m - 1; i >= 0; i--) {
        cout << G[i];
        if (i > 0)cout << ' ';
    }
    cout << "\n" << cnt << endl;
    for(int i = 0; i < N; i++) {
        cout << num[i]<<endl;
    }
    return 0;
}



Compiler output:
a.cc:3:1: error: '__int64' does not name a type; did you mean '__int64_t'?
    3 | __int64 cnt = 0;
      | ^~~~~~~
      | __int64_t
a.cc: In function 'void insertSort(int*, int, int)':
a.cc:13:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   13 |             cnt++;
      |             ^~~
      |             int
a.cc: In function 'int main()':
a.cc:41:21: error: 'cnt' was not declared in this scope; did you mean 'int'?
   41 |     cout << "\n" << cnt << endl;
      |                     ^~~
      |                     int
Language: C++

#include "stdafx.h"
#include <iostream>
#include <cstdio>
using namespace std;

int n;
int a[1000000];

long long insertionSort(int a[], int n, int g, long long cnt) {
	for (int i = g;i < n;i++) {
		int v = a[i];
		int j = i - g;
		while (j >= 0 && v < a[j])
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}

		a[j + g] = v;
	}

	return cnt;
}


void shellSort(int a[], int n) {
	int idx = 0, m;
	long long cnt = 0;
	int g[15];

	g[0] = 1;
	while (g[idx] < n) {
		g[++idx] = 3 * g[idx - 1] + 1;
	}

	m = idx;
	cout << m << endl;

	for (int i = idx - 1;0 <= i;i--) {
		cnt = insertionSort(a, n, g[i], cnt);
		cout << g[i];
		if (i == 0) cout << endl;
		else cout << " ";
	}

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


int main()
{
	cin >> n;

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

	shellSort(a, n);
    return 0;
}



Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include "stdafx.h"
#include <iostream>
#include <cstdio>
using namespace std;

int n;
int a[1000000];

long long insertionSort(int a[], int n, int g, long long cnt) {
	for (int i = g;i < n;i++) {
		int v = a[i];
		int j = i - g;
		while (j >= 0 && v < a[j])
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}

		a[j + g] = v;
	}

	return cnt;
}


void shellSort(int a[], int n) {
	int idx = 0, m;
	long long cnt = 0;
	int g[15];

	g[0] = 1;
	while (g[idx] < n) {
		g[++idx] = 3 * g[idx - 1] + 1;
	}

	m = idx;
	cout << m << endl;

	for (int i = idx - 1;0 <= i;i--) {
		cnt = insertionSort(a, n, g[i], cnt);
		cout << g[i];
		if (i == 0) cout << endl;
		else cout << " ";
	}

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


int main()
{
	cin >> n;

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

	shellSort(a, n);
    return 0;
}



Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

from typing import List


def insertion_sort(arr: List[int], n: int, g: int):
    cnt = 0
    for i in range(g, n):
        v = arr[i]
        j = i - g
        while (j >= 0 and arr[j] > v):
            arr[j + g] = arr[j]
            j = j - g
            cnt += 1

        arr[j + g] = v

    return cnt


def shell_sort(arr, n):
    G = [(3 * i + 1) for i in range(100) if (3 * i + 1) <= n][::-1]
    m = len(G)
    cnt = sum([insertion_sort(arr, n, G[i]) for i in range(m)])
    return m, ' '.join([str(x) for x in G]), cnt


n = int(input())
num_arr = [int(input()) for _ in range(n)]
m, G, cnt = shell_sort(num_arr, n)
print(m)
print(G)
print(cnt)
for x in num_arr:
    print(x)



Compiler output:
a.cc:1:1: error: 'from' does not name a type
    1 | from typing import List
      | ^~~~
Language: C++

#include<stdio.h>
#include<string.h>

struct NUM {
	int cnt;
	int m;
	int G[100];
};

int InsertionSort(int A[], int n, int g) {
	int i, v, j, cnt = 0;
	for (i = g; i < n; i++) {
		v = A[i]; j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j]; j = j - g; cnt++;
		}
		A[j + g] = v;
	}
	return cnt;
}

int dev3(int N) {
	int i = 1;
	while (i < N) {
		i = 3 * i + 1;
		if (3 * i + 1 > N)break;
	}
	return;
}

struct NUM ShellSort(int A[], int n) {
	struct NUM num;
	int cnt = 0;
	int m = 0;
	int G[100];
	for (int i = dev3(n); i > 0; i = (i - 1) / 3) {
		G[m] = i;
		m++;
	}
	for (int i = 0; i < m; i++) {
		cnt += InsertionSort(A, n, G[i]);
	}
	num.cnt = cnt; num.m = m; for (int i = 0; i < m; i++) num.G[i] = G[i];
	return num;
}


int main() {
	int N, A[1000000];
	struct NUM num;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	num = ShellSort(A, N);
	printf("%d\n", num.m);
	for (int i = 0; i < num.m; i++) {
		if (i == num.m - 1) {
			printf("%d\n", num.G[i]);
			break;
		}
		printf("%d ", num.G[i]);
	}
	printf("%d\n", num.cnt);
	for (int i = 0; i < N; i++) {
		printf("%d\n", A[i]);
	}
	return 0;
}


Compiler output:
a.cc: In function 'int dev3(int)':
a.cc:28:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
   28 |         return;
      |         ^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

int cnt;

void insertionSort(vector<int> &v, const int g) {
	int work, k, size = v.size();
	for (int i = g; i < v.size(); ++i) {
		work = v[i];
		k = i - g;
		while (k >= 0 && v[k] > work) {
			v[k + g] = v[k];
			k -= g;
			++cnt;
		}
		v[k + g] = work;
	}
}

void shellSort(vector<int> &v) {
	vector<int> G;
	cnt = 0;
	
	for (int i = 1;;) {
		if (i > v.size()) break;
		G.push_back(i);
		i = 3 * i + 1;
	}
	cout << G.size() << endl;

	reverse(G.begin(), G.end());

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		cout << *itr;
		if (itr != G.end() - 1) cout << " ";
	}
	cout << endl;

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		insertionSort(v, *itr);
	}
}

int main() {
	int n;
	vector<int> v;

	cin >> n;

	v.resize(n);

	for (int i = 0; i < v.size(); ++i)
		scanf_s("%d", v[i]);

	shellSort(v);
	cout << cnt << endl;

	int size = v.size();
	for (int i = 0; i < size; ++i) {
		cout << v[i];
		if (i != size - 1)  cout << endl;
	}
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:53:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   53 |                 scanf_s("%d", v[i]);
      |                 ^~~~~~~
      |                 scanf
Language: C++

#include<bits/stdc++.h>
using namespace std;

int cnt;

void insertionSort(vector<int> &v, const int g) {
	int work, k, size = v.size();
	for (int i = g; i < v.size(); ++i) {
		work = v[i];
		k = i - g;
		while (k >= 0 && v[k] > work) {
			v[k + g] = v[k];
			k -= g;
			++cnt;
		}
		v[k + g] = work;
	}
}

void shellSort(vector<int> &v) {
	vector<int> G;
	cnt = 0;
	
	for (int i = 1;;) {
		if (i > v.size()) break;
		G.push_back(i);
		i = 3 * i + 1;
	}
	cout << G.size() << endl;

	reverse(G.begin(), G.end());

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		cout << *itr;
		if (itr != G.end() - 1) cout << " ";
	}
	cout << endl;

	for (auto itr = G.begin(); itr != G.end(); ++itr) {
		insertionSort(v, *itr);
	}
}

int main() {
	int n;
	vector<int> v;

	cin >> n;

	v.resize(n);

	for (int i = 0; i < v.size(); ++i)
		scanf_s("%d", &v[i]);

	shellSort(v);
	cout << cnt << endl;

	int size = v.size();
	for (int i = 0; i < size; ++i) {
		cout << v[i];
		if (i != size - 1)  cout << endl;
	}
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:53:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   53 |                 scanf_s("%d", &v[i]);
      |                 ^~~~~~~
      |                 scanf
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n - 1; i++) {
    v = A[i];
    j = i - g;
    while ( int j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
}

void shellSort(int A[], int n){
  int h;
  while ( h <= n ) {
    G.push_back(h);
    h += 3*h-1;
  }

  for ( int i = G.size() - 1; i > 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);
  
  cout << G.size()  << endl;

  for ( int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc:11:1: error: 'vector' does not name a type
   11 | vector<int> G;
      | ^~~~~~
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:15:5: error: 'v' was not declared in this scope
   15 |     v = A[i];
      |     ^
a.cc:16:5: error: 'j' was not declared in this scope
   16 |     j = i - g;
      |     ^
a.cc:17:19: error: expected initializer before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:17:18: error: expected ')' before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |           ~      ^~~
      |                  )
a.cc:17:19: error: expected primary-expression before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:25:31: error: a function-definition is not allowed here before '{' token
   25 | void shellSort(int A[], int n){
      |                               ^
a.cc:37:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   37 | int main() {
      |         ^~
a.cc:37:9: note: remove parentheses to default-initialize a variable
   37 | int main() {
      |         ^~
      |         --
a.cc:37:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:37:12: error: a function-definition is not allowed here before '{' token
   37 | int main() {
      |            ^
a.cc:55:2: error: expected '}' at end of input
   55 | }
      |  ^
a.cc:13:42: note: to match this '{'
   13 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n - 1; i++) {
    int v = A[i];
    j = i - g;
    while ( int j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
}

void shellSort(int A[], int n){
  int h;
  while ( h <= n ) {
    G.push_back(h);
    h += 3*h-1;
  }

  for ( int i = G.size() - 1; i > 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);
  
  cout << G.size()  << endl;

  for ( int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc:11:1: error: 'vector' does not name a type
   11 | vector<int> G;
      | ^~~~~~
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:16:5: error: 'j' was not declared in this scope
   16 |     j = i - g;
      |     ^
a.cc:17:19: error: expected initializer before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:17:18: error: expected ')' before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |           ~      ^~~
      |                  )
a.cc:17:19: error: expected primary-expression before '>=' token
   17 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:25:31: error: a function-definition is not allowed here before '{' token
   25 | void shellSort(int A[], int n){
      |                               ^
a.cc:37:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   37 | int main() {
      |         ^~
a.cc:37:9: note: remove parentheses to default-initialize a variable
   37 | int main() {
      |         ^~
      |         --
a.cc:37:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:37:12: error: a function-definition is not allowed here before '{' token
   37 | int main() {
      |            ^
a.cc:55:2: error: expected '}' at end of input
   55 | }
      |  ^
a.cc:13:42: note: to match this '{'
   13 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

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

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n - 1; i++) {
    int v = A[i];
    j = i - g;
    while ( int j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
}

void shellSort(int A[], int n){
  int h;
  while ( h <= n ) {
    G.push_back(h);
    h += 3*h-1;
  }

  for ( int i = G.size() - 1; i > 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);
  
  cout << G.size()  << endl;

  for ( int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:17:5: error: 'j' was not declared in this scope
   17 |     j = i - g;
      |     ^
a.cc:18:19: error: expected initializer before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:18:18: error: expected ')' before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |           ~      ^~~
      |                  )
a.cc:18:19: error: expected primary-expression before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:26:31: error: a function-definition is not allowed here before '{' token
   26 | void shellSort(int A[], int n){
      |                               ^
a.cc:38:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   38 | int main() {
      |         ^~
a.cc:38:9: note: remove parentheses to default-initialize a variable
   38 | int main() {
      |         ^~
      |         --
a.cc:38:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:38:12: error: a function-definition is not allowed here before '{' token
   38 | int main() {
      |            ^
a.cc:56:2: error: expected '}' at end of input
   56 | }
      |  ^
a.cc:14:42: note: to match this '{'
   14 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

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

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n - 1; i++) {
    int v = A[i];
    int j = i - g;
    while ( int j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
}

void shellSort(int A[], int n){
  int h;
  while ( h <= n ) {
    G.push_back(h);
    h += 3*h-1;
  }

  for ( int i = G.size() - 1; i > 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);
  
  cout << G.size()  << endl;

  for ( int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:18:19: error: expected initializer before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:18:18: error: expected ')' before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |           ~      ^~~
      |                  )
a.cc:18:19: error: expected primary-expression before '>=' token
   18 |     while ( int j >= 0 && A[j] > v) {
      |                   ^~
a.cc:26:31: error: a function-definition is not allowed here before '{' token
   26 | void shellSort(int A[], int n){
      |                               ^
a.cc:38:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   38 | int main() {
      |         ^~
a.cc:38:9: note: remove parentheses to default-initialize a variable
   38 | int main() {
      |         ^~
      |         --
a.cc:38:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:38:12: error: a function-definition is not allowed here before '{' token
   38 | int main() {
      |            ^
a.cc:56:2: error: expected '}' at end of input
   56 | }
      |  ^
a.cc:14:42: note: to match this '{'
   14 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

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

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
  for ( int i = g; i < n - 1; i++) {
    int v = A[i];
    int j = i - g;
    while ( j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
}

void shellSort(int A[], int n){
  int h;
  while ( h <= n ) {
    G.push_back(h);
    h += 3*h-1;
  }

  for ( int i = G.size() - 1; i > 0; i--) {
    insertionSort(A, n, G[i]);
  }
}

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

  shellSort(A, n);
  
  cout << G.size()  << endl;

  for ( int i = G.size() - 1; i >= 0; i--) {
    printf("%d", G[i]);
    if ( i ) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for ( int i = 0; i < n; i++ ) printf("%d\n", A[i]);

  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(int*, int, int)':
a.cc:26:31: error: a function-definition is not allowed here before '{' token
   26 | void shellSort(int A[], int n){
      |                               ^
a.cc:38:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   38 | int main() {
      |         ^~
a.cc:38:9: note: remove parentheses to default-initialize a variable
   38 | int main() {
      |         ^~
      |         --
a.cc:38:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:38:12: error: a function-definition is not allowed here before '{' token
   38 | int main() {
      |            ^
a.cc:56:2: error: expected '}' at end of input
   56 | }
      |  ^
a.cc:14:42: note: to match this '{'
   14 | void insertionSort(int A[], int n, int g){
      |                                          ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

long long cnt;
vector<int> G;

void insertionSort(vector<int>& A, g) {
  for (int i = g; i < A.size(); i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0; && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(vector<int>& A) {
  for (int h = 1; ;) {
    if (h > A.size()) {
      break;
    }
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int  i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, G[i]);
  }
}

int main(){
  vector<int> A;
  A.reserve(100000);

  int N, a;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  cnt = 0;

  shellSort(A);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    cout << G[i];
    if (i) {
      cout << " ";
    }
  }
  cout << endl;
  cout << cnt;
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << endl;
  }

  return 0;
}


Compiler output:
a.cc:8:36: error: 'g' has not been declared
    8 | void insertionSort(vector<int>& A, g) {
      |                                    ^
a.cc: In function 'void insertionSort(std::vector<int>&, int)':
a.cc:9:16: error: 'g' was not declared in this scope
    9 |   for (int i = g; i < A.size(); i++) {
      |                ^
a.cc:12:18: error: expected ')' before ';' token
   12 |     while (j >= 0; && A[j] > v) {
      |           ~      ^
      |                  )
a.cc:12:24: error: expected ';' before '[' token
   12 |     while (j >= 0; && A[j] > v) {
      |                        ^
      |                        ;
a.cc:12:23: error: label 'A' used but not defined
   12 |     while (j >= 0; && A[j] > v) {
      |                       ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

long long cnt;
vector<int> G;

void insertionSort(vector<int>& A, int g) {
  for (int i = g; i < A.size(); i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0; && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(vector<int>& A) {
  for (int h = 1; ;) {
    if (h > A.size()) {
      break;
    }
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int  i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, G[i]);
  }
}

int main(){
  vector<int> A;
  A.reserve(100000);

  int N, a;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  cnt = 0;

  shellSort(A);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    cout << G[i];
    if (i) {
      cout << " ";
    }
  }
  cout << endl;
  cout << cnt;
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'void insertionSort(std::vector<int>&, int)':
a.cc:12:18: error: expected ')' before ';' token
   12 |     while (j >= 0; && A[j] > v) {
      |           ~      ^
      |                  )
a.cc:12:24: error: expected ';' before '[' token
   12 |     while (j >= 0; && A[j] > v) {
      |                        ^
      |                        ;
a.cc:12:23: error: label 'A' used but not defined
   12 |     while (j >= 0; && A[j] > v) {
      |                       ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

long long cnt;
vector<int> G;

void insertionSort(vector<int>& A, int g) {
  for (int i = g; i < A.size(); i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }
}

void shellSort(vector<int>& A) {
  for (int h = 1; ;) {
    if (h > A.size()) {
      break;
    }
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int  i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, G[i]);
  }
}

int main(){
  vector<int> A;
  A.reserve(100000);

  int N, a;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  cnt = 0;

  shellSort(A);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--) {
    cout << G[i];
    if (i) {
      cout << " ";
    }
  }
  cout << endl;
  cout << cnt << endl
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:22: error: expected ';' before 'for'
   58 |   cout << cnt << endl
      |                      ^
      |                      ;
   59 |   for (int i = 0; i < A.size(); i++) {
      |   ~~~                 
a.cc:59:19: error: 'i' was not declared in this scope
   59 |   for (int i = 0; i < A.size(); i++) {
      |                   ^
Language: C++

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<algorithm>
using namespace std;

int cnt = 0;

void insertionSort(int a[], int n, int g) {
	int i, j;
	for (i = g; i < n; i++) {
		j = i;
		int v = a[i];
		while (j-g >= 0 && a[j - g] > v) {
			a[j] = a[j - g];
			j -= g;
			cnt++;
		}
		a[j] = v;
	}

}


int main()
{
	int a[101], g[3] = { 3,1 };
	int m = 2;
	int n, i, j;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> a[i];
	if (n >= 4) {
		cout << m << endl;
		for (i = 0; i < m; i++) {
			insertionSort(a, n, g[i]);
		}
		cout << "3 1\n" << cnt << endl;
		for (i = 0; i < n; i++)
			cout << a[i] << endl;
	}
	else {
		cout << 1 << endl;
		for (i = 0; i < 3; i++) {
			insertionSort(a, n, g[i]);
		}
		cout << "1\n" << cnt << endl;
		for (i = 0; i < n; i++)
			cout << a[i] << endl;
	}
    return 0;
}




Compiler output:
a.cc:4:10: fatal error: stdafx.h: No such file or directory
    4 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <stdio.h>
using namespace std;

int insertionSort(int *A, int n, int g, int cnt) {
    for (int i=g; i<N; i++) {
        int v = A[i];
        int j = i - g;
        
        while(j>=0 && A[j]>v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    
    return cnt;
}


void shellSort(int *A, int n) {
    int cnt = 0;
    int m = (int)(sqrt(n));
    int G[m];
    
    G[0] = n-1;
    for (int i=0; i<m; i++) {
        if(i>0) G[m] = (int)(G[m]/2);
        if(i==m) G[m] = 1;
        cnt = insertionSort(A, n , G[i], cnt);
    }
    
    printf("%d\n", m);
    printf("%d", G[0]);
    for (int i=1; i<m; i++) printf(" %d", G[i]);
    printf("\n");
}


int main() {
    int n;
    scanf("%d", &n);
    
    int a[n];
    for (int i=0; i<n; i++) scanf("%d", &a[i]);
    
    shellSort(a, n);
    
    for (int i=0; i<n; i++) printf("%d\n", a[i]);
    
    return 0;
}





Compiler output:
a.cc: In function 'int insertionSort(int*, int, int, int)':
a.cc:5:21: error: 'N' was not declared in this scope
    5 |     for (int i=g; i<N; i++) {
      |                     ^
a.cc: In function 'void shellSort(int*, int)':
a.cc:23:19: error: 'sqrt' was not declared in this scope
   23 |     int m = (int)(sqrt(n));
      |                   ^~~~