alexjercan/bugnet huggingface dataset:
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_INPUT_SIZE 1024
#define INPUT_FROM_FILE

int *createArray(int size, char *input);
void insertionSort(int size, int *array);
void trace(int size, int *array);

int main(int argc, char *argv[]) {
  char input[MAX_INPUT_SIZE];

  int size = atoi(fgets(input, sizeof(input), stdin));
  // printf("array size : %d\\n", size);

  while ((fgets(input, sizeof(input), stdin)) != NULL) {
    int *array = createArray(size, input);
    insertionSort(size, array);

    if (array != NULL) {
      delete[] array;
    }
  }

  return 0;
}

int *createArray(int size, char *input) {
  int *array = new int[size];

  if (array != NULL) {
    for (int i = 0; i < size; i++) {
      array[i] = i == 0 ? atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
    }
  }

  return array;
}

void insertionSort(int size, int *array) {
  for (int i = 0; i < size; i++) {
    int key = array[i];
    int j = i - 1;
    while (j >= 0 && array[j] > key) {
      array[j + 1] = array[j];
      j--;
    }
    array[j + 1] = key;
    trace(size, array);
  }
}

void trace(int size, int *array) {
  for (int i = 0; i < size; i++) {
    if (i != 0)
      printf(" ");
    printf("%d", array[i]);
  }
  printf("\\n");
}

Error: 1
Cannot open file, program exit


Fixed submission:

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

#define MAX_INPUT_SIZE 1024
#define INPUT_FROM_FILE

int *createArray(int size, char *input);
void insertionSort(int size, int *array);
void trace(int size, int *array);

int main(int argc, char *argv[]) {
  char input[MAX_INPUT_SIZE];
#ifdef INPUT_FROM_FILE
  FILE *fp = NULL;

  if ((fp = fopen("input.txt", "r")) == NULL) {
    fprintf(stderr, "Cannot open file, program exit\\n");
    exit(1);
  }

  int size = atoi(fgets(input, sizeof(input), fp));
  // printf("array size : %d\\n", size);

  while ((fgets(input, sizeof(input), fp)) != NULL) {
    int *array = createArray(size, input);
    insertionSort(size, array);

    if (array != NULL) {
      delete[] array;
    }
  }

  if (fp != NULL) {
    fclose(fp);
    fp = NULL;
  }
#else
  while (fgets(input, sizeof(input), stdin) != NULL) {
  }
#endif

  return 0;
}

int *createArray(int size, char *input) {
  int *array = new int[size];

  if (array != NULL) {
    for (int i = 0; i < size; i++) {
      array[i] = i == 0 ? atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
    }
  }

  return array;
}

void insertionSort(int size, int *array) {
  for (int i = 0; i < size; i++) {
    int key = array[i];
    int j = i - 1;
    while (j >= 0 && array[j] > key) {
      array[j + 1] = array[j];
      j--;
    }
    array[j + 1] = key;
    trace(size, array);
  }
}

void trace(int size, int *array) {
  for (int i = 0; i < size; i++) {
    if (i != 0)
      printf(" ");
    printf("%d", array[i]);
  }
  printf("\\n");
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_INPUT_SIZE 1024
#define INPUT_FROM_FILE

int *createArray(int size, char *input);
void insertionSort(int size, int *array);

int main(int argc, char *argv[]) {
  char input[MAX_INPUT_SIZE];

  int size = atoi(fgets(input, sizeof(input), stdin));
  // printf("array size : %d\\n", size);

  while ((fgets(input, sizeof(input), stdin)) != NULL) {
    int *array = createArray(size, input);
    insertionSort(size, array);

    if (array != NULL) {
      delete[] array;
    }
  }

  return 0;
}

int *createArray(int size, char *input) {
  int *array = new int[size];

  if (array != NULL) {
    for (int i = 0; i < size; i++) {
      array[i] = i == 0 ? atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
    }
  }

  return array;
}

void insertionSort(int size, int *array) {
  for (int i = 0; i < size; i++) {
    int curNum = array[i];
    for (int j = i - 1; j >= 0; j--) {
      if (curNum > array[j]) {
        array[j + 1] = curNum;
        break;
      } else {
        array[j + 1] = array[j];
        array[j] = curNum;
      }
    }
    for (int i = 0; i < size; i++) {
      if (i != 0)
        printf(" ");
      printf("%d", array[i]);
    }
    printf("\\n");
  }
}

Error: -11

Fixed submission:

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

#define MAX_INPUT_SIZE 1024
#define INPUT_FROM_FILE

int *createArray(int size, char *input);
void insertionSort(int size, int *array);

int main(int argc, char *argv[]) {
  char input[MAX_INPUT_SIZE];

  int size = atoi(fgets(input, sizeof(input), stdin));
  // printf("array size : %d\\n", size);

  // while ((fgets(input, sizeof(input), stdin)) != NULL) {
  int *array = createArray(size, input);
  insertionSort(size, array);

  if (array != NULL) {
    delete[] array;
  }
  //    }

  return 0;
}

int *createArray(int size, char *input) {
  int *array = new int[size];

  if (array != NULL) {
    for (int i = 0; i < size; i++) {
      array[i] = i == 0 ? atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
    }
  }
  return array;
}

void insertionSort(int size, int *array) {
  for (int i = 0; i < size; i++) {
    int curNum = array[i];
    for (int j = i - 1; j >= 0; j--) {
      if (curNum > array[j]) {
        array[j + 1] = curNum;
        break;
      } else {
        array[j + 1] = array[j];
        array[j] = curNum;
      }
    }
    for (int i = 0; i < size; i++) {
      printf("%d ", array[i]);
    }
    printf("\\n");
  }
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 0; i < n; i++) {
    int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    for (int k = 0; k < n - 1; k++)
      cout << a[k] << " ";
    cout << a[n - 1] << endl;
  }
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

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

  for (int i = 0; i < n; i++) {
    int v = a[i];
    int j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    for (int k = 0; k < n; k++) {
      if (k > 0)
        cout << " ";
      cout << a[k];
    }
    cout << endl;
  }
  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
void trace(int A[], int N) {
  int i;
  for (i = 0; i < N; i++) {
    if (i > 0)
      printf(" ");
    printf("%d", A[i]);
  }
  printf("\\n");
}

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

int main(void) {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i = 0; i < N; i++)
    scanf("%d", &A[i]);
  trace(A, N);
  insertionSort(A, N);

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

void trace(int A[], int N) {
  int i;
  for (i = 0; N - 1; i++) {
    if (i > 0)
      putchar(' ');
    printf("%d", A[i]);
  }
  printf("\\n");
}

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

int main(void) {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i = 0; N - 1; i++)
    scanf("%d", &A[i]);
  trace(A, N);
  insertionSort(A, N);

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int q, i, j, k, key;
  int array[100];
  cin >> q;
  for (i = 0; i < q; i++)
    cin >> array[i];
  for (i = 1; i < q; i++) {
    for (int j = 0; j < q; j++) {
      cout << array[j];
      if (j == q - 1)
        cout << endl;
      else
        cout << " ";
    }
    key = array[i];
    j = i - 1;
    while (j >= 0 && array[j] > key) {
      array[j + 1] = array[j];
      j--;
      array[j + 1] = key;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << array[i];
    if (i == q - 1)
      cout << endl;
    else
      cout << " ";
  }
}

Error: -11

Fixed submission:

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

int main() {
  int q, i, j, k, key;
  string array;
  cin >> q;
  for (i = 0; i < q; i++)
    cin >> array[i];
  for (i = 1; i < array.length() - 1; i++) {
    key = array[i];
    j = i - 1;
    while (j >= 0 && array[j] > key) {
      array[j + 1] = array[j];
      j--;
      array[j + 1] = key;
    }
    for (k = 0; k < q; k++) {
      if (k = q - 1)
        cout << array[k] << endl;
      else
        cout << array[k] << " ";
    }
  }
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

static const int N = 1000;

void print(int a[], int n) {
  int k;
  for (k = 0; k < n; k++) {
    if (k > 0)
      printf(" ");
    printf("%d", a[k]);
  }
  printf("\\n");
}

int main(void) {
  int n, i, j, key;
  int a[N + 1];
  scanf("%d", &n);
  // input
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  print(a, n);

  // insertion
  for (i = 1; i < n; i++) {
    key = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > key) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = key;
    print(a, n);
  }

  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>

static const int N = 1000;

void print(int a[], int n) {
  int k;
  for (k = 0; k < n; k++) {
    if (k > 0)
      printf(" ");
    printf("%d", a[k]);
  }
  printf("\\n");
}

int main(void) {
  int n, i, j, key;
  int a[N + 1];
  scanf("%d", &n);
  // input
  for (i = 0; i < n; i++) {
    scanf("%d", a[i]);
  }
  print(a, n);

  // insertion
  for (i = 1; i < n; i++) {
    key = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > key) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = key;
    print(a, n);
  }

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

int main() {
  int n;
  int A[1000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  outlist(A, n);
  for (int j = 1; j < n; j++) {
    int v = A[j];
    int k = j - 1;
    while (k >= 0 && A[k] > v) {
      A[k + 1] = A[k];
      k--;
    }
    A[k + 1] = v;
    outlist(A, n);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {
  int n;
  int A[1000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  outlist(A, n);
  for (int j = 1; j < n; j++) {
    int v = A[j];
    int k = j - 1;
    while (k >= 0 && A[k] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    outlist(A, n);
  }
  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
void print(int *num, int n) {
  for (int i = 0; i < n; i++) {
    if (i > 0)
      cout << ' ';
    cout << num[i];
  }
  cout << endl;
}
void insertSort(int *num, int n) {
  int tmp;
  for (int i = 1; i < n; i++) {
    tmp = num[i];
    int j = i - 1;
    while (j >= 0 && num[j] > tmp) {
      num[j + 1] = num[j];
      j--;
    }
    num[j + 1] = tmp;
    print(num, n);
  }
}
int main() {
  int n;
  int num[100];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> num[i];
  print(num, n);
  insertSort(num, n);
}

Error: -11

Fixed submission:

#include <stdio.h>
int a[105];
int n;
void mmp() {
  for (int i = 0; i < n; i++) {
    if (i > 0)
      printf(" ");
    printf("%d", a[i]);
  }
  printf("\\n");
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  mmp();
  for (int i = 1; i < n; i++) {
    int j = 0;
    int sb = a[i];
    while (a[j] <= a[i])
      ++j;
    for (int k = i - 1; k >= j; k--) {
      a[k + 1] = a[k];
    }
    a[j] = sb;
    mmp();
  }
  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef signed long long ll;

int main(void) {
  int N = 0;

  cin >> N;

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

  for (int i = 1; i < N; i++) {
    int value = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > value) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = value;
    for (int k = 0; k < N; k++) {
      if (k > 0) {
        cout << " ";
      }
      cout << A[k];
    }
    cout << endl;
  }

  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef signed long long ll;

int main(void) {
  int N = 0;

  cin >> N;

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

  for (int i = 1; i < N; i++) {
    int value = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > value) {
      A[j + 1] = A[j];
      j--;
    }
    A[j] = value;
    for (int k = 0; k < N; k++) {
      if (k > 0) {
        cout << " ";
      }
      cout << A[k];
    }
    cout << endl;
  }

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

void showArray(int *datas, int n) {
  int i;
  for (i = 0; i < n - 1; i++) {
    cout << datas[i] << " ";
  }
  cout << datas[n - 1] << endl;
}
int main() {
  int n, i, j, k, key;
  cin >> n;
  int datas[1000];
  for (i = 0; i < n; i++) {
    cin >> datas[i];
  }

  for (j = 1; j < n; j++) {
    showArray(datas, n);
    key = datas[j];
    for (k = j - 1; k >= 0; k--) {
      if (datas[k] < key) {
        break;
      }
      datas[k + 1] = datas[k];
      datas[k] = key;
    }
  }
  showArray(datas, n);
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i, j, k, key;
  cin >> n;
  int datas[n];
  for (i = 0; i++; i < n) {
    cin >> datas[i];
  }

  for (j = 1; j++; j < n) {
    key = datas[j];
    for (k = j - 1; k--; k >= 0) {
      if (datas[k] < key)
        break;
      datas[k + 1] = datas[k];
      datas[k] = key;
    }
    for (i = 0; i++; i < n) {
      cout << datas[i];
    }
  }
}
Problem p02255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;
static const int N = 100;

void printArray(int a[], int n) {
  int k = 0;
  while (1) {
    if (k == n - 1)
      break;
    else {
      printf("%d ", a[k]);
    }
    k++;
  }
  printf("%d\\n", a[n - 1]);
}

int main(int argc, char const *argv[]) {
  int A[N];
  int v, j, n;

  cin >> n;

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;
static const int N = 100;

void printArray(int a[], int n) {
  int k = 0;
  while (1) {
    if (k == n - 1)
      break;
    else {
      printf("%d ", a[k]);
    }
  }
  printf("%d\\n", a[n - 1]);
}

int main(int argc, char const *argv[]) {
  int A[N];
  int v, j;

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

  printArray(A, N);
  for (int i = 1; i < N; ++i) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      A[j] = v;
      j--;
    }
    printArray(A, N);
  }

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

void printarray(vector<int> &a, int n) {
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
}

int main() {
  int n;
  vector<int> a(100);
  cin >> n;

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

  printarray(a, n);
  for (int i = 1; i < n; i++) {
    int key = a[i];
    int j;
    for (j = i - 1; j >= 0 && a[j] > key; j--) {
      a[j + 1] = a[j];
    }
    a[j + 1] = key;
    printarray(a, n);
  }
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

void printarray(vector<int> &a) {
  for (int x : a) {
    cout << x << " ";
  }
  cout << endl;
}

int main() {
  int n;
  vector<int> a(100);
  cin >> n;

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

  printarray(a);

  for (int i = 1; i < n; i++) {
    int key = a[i];
    int j;
    for (j = i - 1; j >= 0 && a[j] > key; j--) {
      a[j + 1] = a[j];
    }
    a[j] = key;
    printarray(a);
  }
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <fstream>
#include <iostream>

using namespace std;

void printArray(int A[], int num) {
  for (int j = 0; j < num; j++) {
    if (j > 0)
      printf(" ");
    printf("%d", A[j]);
  }
  printf("\\n");
}

void insertionSort(int A[], int num) {
  int j, i;

  for (i = 1; i < num; i++) {
    j = i - 1;
    while (j >= 0) {
      if (A[j] > A[j + 1]) {
        swap(A[j], A[j + 1]);
      }
      j--;
    }
    printArray(A, num);
  }
}

int main() {

  int num;
  int A[100];

  cin >> num;

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

  printArray(A, num);

  insertionSort(A, num);

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>

using namespace std;

void printArray(int A[], int num) {
  for (int j = 0; j < num; j++) {
    printf("%d", A[j]);
  }
  printf("\\n");
}

void insertionSort(int A[], int num) {
  int j, i;

  for (i = 1; i < num; i++) {
    j = i - 1;
    while (j >= 0) {
      if (A[j] > A[j + 1]) {
        swap(A[j], A[j + 1]);
      }
      j--;
    }
    printArray(A, num);
  }
}

int main() {
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());

  int num;
  int A[100];

  cin >> num;

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

  printArray(A, num);

  insertionSort(A, num);

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

void printArr(int *arr, int size) {
  for (int i = 0; i < size; i++) {
    if (i != 0)
      printf(" ");
    printf("%d", arr[i]);
  }
  printf("\\n");
}

void insertionSort(int *arr, int size) {
  for (int i = 1; i < size; i++) {
    int j = i - 1;
    int v = arr[i];
    while (j >= 0 && arr[j] > v) {
      arr[j + 1] = arr[j];
      j--;
    }
    arr[j + 1] = v;
    printArr(arr, size);
  }
}

int main() {
  int arr[100];
  int N = 0;

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

  printArr(arr, N);
  insertionSort(arr, N);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

void trace(int arr[], int size) {
  int i;
  for (i = 0; i < size; i++) {
    printf("%d ", arr[i]);
  }
  printf("\\n");
}

void insertionSort(int *arr, int size) {
  for (int i = 1; i < size; i++) {

    int j = i - 1;
    int v = arr[i];
    while (j >= 0 && arr[j] > v) {
      arr[j + 1] = arr[j];
      j--;
    }
    arr[j + 1] = v;
    trace(arr, size);
    printf("\\n");
  }
}

int main() {
  int arr[100];
  int N = 0;

  /*
  N = 5;
  arr[0] = 8;
  arr[1] = 6;
  arr[2] = 3;
  arr[3] = 9;
  arr[4] = 7;
  */
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &arr[i]);

  trace(arr, N);
  insertionSort(arr, N);

  while (true) {
  }
  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

void show(vector<int> a) {
  for (int i = 0; i < a.size() - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[a.size() - 1] << endl;
}

vector<int> isort(vector<int> a, int n) {
  int v = 0;
  int j;
  show(a);
  for (int i = 1; i < n; i++) {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    show(a);
  }
  return a;
}

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  isort(a, n);

  return 0;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

void show(vector<int> a) {
  for (int i = 0; i < a.size() - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[a.size() - 1] << endl;
}

vector<int> isort(vector<int> a, int n) {
  int v = 0;
  int j;
  show(a);
  for (int i = 1; i < n; i++) {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    show(a);
  }
}

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  isort(a, n);

  return 0;
}
Problem p02255 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[105];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cout << a[i] << (i == n - 1 ? '\\n' : ' ');
  int k;
  for (int i = 1; i < n; i++) {
    k = a[i];
    int j;
    for (j = i - 1; j < n && a[j] > k; j--)
      a[j + 1] = a[j];
    a[j + 1] = k;
    for (int i = 0; i < n; i++)
      cout << a[i] << (i == n - 1 ? '\\n' : ' ');
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
typedef long long ll;
using namespace std;

void solve() {
  int n;
  cin >> n;
  int a[105];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cout << a[i] << ' ';
  cout << endl;
  int k;
  for (int i = 1; i < n; i++) {
    k = a[i];
    int j;
    for (j = i - 1; j < n && a[j] > k; j--)
      a[j + 1] = a[j];
    a[j + 1] = k;
    for (int i = 0; i < n; i++)
      cout << a[i] << ' ';
    cout << endl;
  }
}
int main() {
  solve();
  return 0;
}