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

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

int n;
int main() {
  cin >> n;
  int a1 = 0;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    cin >> a1;
    a.push_back(a1);
  }
  reverse(a.begin(), a.end());
  for (int j = 0; j < n; ++j) {
    if (j < n - 1) {
      cout << a[j] << " ";
    } else {
      cout << a[n - 1];
    }
  }
  cout << endl;
  return 0;
}


Error: -11

Fixed submission:

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

int n;
int main() {
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a.push_back(a[i]);
  }
  reverse(a.begin(), a.end());
  for (int j = 0; j < n; ++j) {
    if (j < n - 1) {
      cout << a[j] << " ";
    } else {
      cout << a[n - 1];
    }
  }
  cout << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, num[100];
  cin >> n;

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, num[n], num2[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    for (int j = 0; j < n; j++) {
      num2[j] = num[i];
      i--;
      cout << num2[j] << endl;
    }
  }

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

#include "iostream"
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i > 0) {
      cout << a[i] << " ";
    } else {
      cout << a[i];
    }
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include "iostream"
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100];
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (size_t i = n - 1; i >= 0; i--) {
    if (i > 0) {
      cout << " " << a[i];
    } else {
      cout << a[i];
    }
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int num;
  int data[100];
  scanf("%d", &num);

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

  for (int i = num - 1; i > -1; i--) {
    if (i == num - 1) {
      cout << data[i];
    } else {
      cout << " " << data[i];
    }
  }
  printf("\\n");
  return 0;
}


Error: -11

Fixed submission:

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

int main() {

  int num, rp;
  int ans;
  cin >> num;
  vector<int> data;

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

  for (int i = num - 1; i == 0; i--) {
    cout << data[i];
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> in(n);
  rep(i, n) cin >> in[i];
  rep(i, n - 1) cout << in[n - i - 1] << " ";
  cout << in[0] << endl;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;
int main() {
  int n;
  vector<int> in(n);
  rep(i, n) cin >> in[i];
  rep(i, n - 1) cout << in[n - i - 1] << " ";
  cout << in[0] << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = n - 1; 0 < i; i--)
    cout << a[i] << " ";
  cout << a[0] << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, m;
  int maximum;
  int a[1000];
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    maximum = 0;
    for (int j = 0; j < n; j++) {
      cin >> a[j];
    }
    for (int j = 0; j < n - 1; j++) {
      for (int t = j + 1; t < n; t++) {
        if (a[j] + a[t] <= m) {
          maximum = max(maximum, a[j] + a[t]);
        }
      }
    }
    if (maximum == 0) {
      cout << "NONE" << endl;
    } else {
      cout << maximum << endl;
    }
  }
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = n - 1; i > 0; i--)
    cout << a[i] << " ";
  cout << a[0] << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = n - 1; i > 0; i++)
    cout << a[i] << " ";
  cout << a[0] << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> numbers(n);
  for (int i = 0; i < n; i++) {
    cin >> numbers[i];
  }
  for (int i = n; i > 1; i--) {
    cout << numbers[i - 1] << ' ';
  }
  cout << numbers[0] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> numbers(n - 1);
  for (int i = 0; i < n; i++) {
    cin >> numbers[i];
  }
  for (int i = n; i > 1; i--) {
    cout << numbers[i - 1] << ' ';
  }
  cout << numbers[0] << endl;

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

#include <stdio.h>

int main(void) {
  int n, i, j, k;
  scanf("%d", &n);
  int retsu[n];
  for (i = 1; i <= n; i++) {
    k = n - i;
    scanf("%d", &retsu[k]);
  }
  for (j = 0; j < n; j++) {
    if (j)
      printf(" ");
    printf("%d", retsu[j]);
  }
  printf("\\n");
  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, i, j, k;
  scanf("%d", &n);
  int retsu[n];
  for (i = 1; i <= n; i++) {
    k = n - i;
    scanf("%d", retsu[k]);
  }
  for (j = 0; j < n; j++) {
    printf("%d ", retsu[j]);
  }
  printf("\\n");
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

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

  for (int i = n - 1; i >= 0; i--) {
    if (i != 0) {
      printf("%d ", array[i]);
    } else {
      printf("%d\\n", array[i]);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

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

  for (int i = n - 1; i >= 0; i++) {
    if (i != 0) {
      printf("%d ", array[i]);
    } else {
      printf("%d\\n");
    }
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i > 1; i--) {
    cout << a[i] << " ";
  }
  cout << a[1] << endl;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int n;
  int a[n];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i > 1; i--) {
    cout << a[i] << " ";
  }
  cout << a[1] << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, s;
  vector<int> a;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n / 2; ++i) {
    s = a[i];
    a[i] = a[n - 1 - i];
    a[n - 1 - i] = s;
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cout << a[i] << endl;
    else
      cout << a[i] << " ";
  }
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n, s;
  vector<int> a;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n / 2; i++) {
    s = a[i];
    a[i] = a[n - i];
    a[n - i] = s;
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cout << a[i] << endl;
    else
      cout << a[i] << " ";
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error



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

int main(void) {

  int n;
  cin >> n;

  vector<int> v(n);

  for (int unsigned i = 0; i < v.size(); i++) {
    cin >> v[i];
  }

  for (int unsigned i = 0; i < v.size(); i++) {
    cout << v[n - i - 1];
    if (i == n - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  // system("pause");
  return 0;
}

Error: -11

Fixed submission:


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

int main(void) {

  int n;
  cin >> n;

  vector<int> v;

  for (int unsigned i = 0; i < v.size(); i++) {
    cin >> v[i];
  }

  cout << v[n - 1];
  for (int unsigned i = 1; i < v.size(); i++) {
    cout << " " << v[n - i - 1];
  }
  cout << endl;
  // system("pause");
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, a;
  cin >> n;
  int ns[n];
  for (int i = 0; i < n; ++i) {
    cin >> a;
    ns[i] = a;
  }
  for (int j = 0; j < n; ++j) {
    if (j > 0)
      cout << " ";
    cout << ns[n - j - 1];
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n; 1 <= i; i++) {
    if (i)
      cout << " ";
    cout << a[i];
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

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

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

  // sort(v.begin(), v.end(), greater<int>());

  vector<int>::reverse_iterator it, end;
  for (it = v.rbegin(), end = v.rend(); it != end; ++it) {
    if (it == v.rbegin())
      cout << (*it);
    else
      cout << " " << (*it);
  }
  cout << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

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

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

  // sort(v.begin(), v.end(), greater<int>());

  vector<int>::reverse_iterator it, end;
  for (it = v.rbegin(), end = v.rend(); it != end; --it) {
    cout << (*it) << " ";
  }
  cout << endl;

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

#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

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

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

  printf("\\n");

  return 0;
}

Error: -11

Fixed submission:


#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", n);

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

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

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  for (int i = n - 1; i >= 0; --i) {
    if (i != n - 1)
      cout << " ";
    cout << v[i];
  }
  cout << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  vector<int> p(n, 0);
  for (int i = 0; i < n; ++i)
    cin >> p[i];
  for (int i = n - 1; i > 0; --i)
    cout << p[i] << " ";
  cout << p[0] << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 100

int main(void) {
  int n, a[MAX], i = 0;
  do {
    cin >> n;
  } while (n > MAX || n < 0);

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

  while (1) {
    printf("%d", a[n - i - 1]);
    if (i++ == n - 1)
      break;
    printf(" ");
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 100

int main(void) {
  int n, a[MAX], i = 0;
  do {
    cin >> n;
  } while (n > MAX || n < 0);

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

  while (1) {
    printf("%d", a[n - i]);
    if (i == n)
      break;
    printf(" ");
  }
  printf("\\n");
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == n - 1) {
      cout << a[i];
      for (i = n - 2; i >= 0; i--) {
        cout << " " << a[i];
      }
      cout << endl;
      break;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == n - 1) {
      cout << a[i];
      for (i = n - 2; i >= 0; i--) {
        cout << " " << a[i];
      }
    }
  }
  return 0;
}
Problem p02407 (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 = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i != 0)
      cout << ' ';
  }
  cout << endl;

  return 0;
}

Error: -11

Fixed submission:

#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 = n - 1; n >= 0; i--) {
    if (i != n - 1)
      cout << " ";
    cout << a[i];
  }
  cout << endl;

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

#include <stdio.h>
int main() {
  int a[100], s, i = 0;
  scanf("%d", &s);
  while (i < s) {
    scanf("%d", &a[i]);
    i++;
  }
  i--;
  for (; i > -1; i--) {
    printf("%d", a[i]);
    if (i != 0)
      printf(" ");
  }
  printf("\\n");
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int a[100], s, i = 0;
  scanf("%d", &s);
  while (i < s) {
    scanf("%d", &a[i]);
    i++;
  }
  i--;
  for (; i = -1; i--) {
    printf("%d", a[i]);
  }
  printf("\\n");
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  if (n % 2 == 0) {
    for (int j = 1; j <= n / 2; j++)
      std::swap(a[j], a[n - j + 1]);
  } else {
    for (int j = 1; j <= (n - 1) / 2; j++)
      std::swap(a[j], a[n - j + 1]);
  }
  for (int k = 1; k < n; k++)
    std::cout << a[k] << " ";
  cout << a[n] << endl;
}


Error: -11

Fixed submission:

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

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  if (n % 2 == 0) {
    for (int i = 1; i <= n / 2; i++)
      std::swap(a[i], a[n - i]);
  } else {
    for (int i = 1; i <= (n - 1) / 2; i++)
      std::swap(a[i], a[n - i]);
  }
  for (int i = 1; 1 <= n; i++)
    std::cout << a[i] << " ";
  cout << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
// #define NDEBUG

int main(void) {
  using namespace std;
  static const int INPUT_N_MAX = 100; /* 前提条件 */
  static const int INPUT_A_MIN = 0;
  static const int INPUT_A_MAX = 1000;

  int input_n = 0;                               /* 数列の長さ */
  cin >> input_n;                                /* 入力の整数n */
  assert(0 < input_n && input_n <= INPUT_N_MAX); /* 前提条件 */
  int a[input_n - 1];

  /* 入力 a[0]から順に格納 */
  for (int i = 0; i < input_n; i++) {
    cin >> a[i];
    assert(INPUT_A_MIN <= a[i] && a[i] < INPUT_A_MAX); /* 前提条件 */
  }
  /* 出力 a[input_n-1]から降順に出力 */
  cout << a[input_n - 1];
  for (int i = input_n - 2; i >= 0; i--) {
    cout << " " << a[i];
  }
  cout << endl;
  return 0;
}


Error: -6
28a5416a-2578-4e9f-8043-6b6c7a8b61d6.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02407/C++/s043895631.cpp:19: int main(): Assertion `INPUT_A_MIN <= a[i] && a[i] < INPUT_A_MAX' failed.


Fixed submission:

#include <cassert>
#include <iostream>
// #define NDEBUG

int main(void) {
  using namespace std;
  static const int INPUT_N_MAX = 100; /* 前提条件 */
  static const int INPUT_A_MIN = 0;
  static const int INPUT_A_MAX = 1000;

  int input_n = 0;                               /* 数列の長さ */
  cin >> input_n;                                /* 入力の整数n */
  assert(0 < input_n && input_n <= INPUT_N_MAX); /* 前提条件 */
  int a[input_n];

  /* 入力 a[0]から順に格納 */
  for (int i = 0; i <= input_n; i++) {
    cin >> a[i];
    assert(INPUT_A_MIN <= a[i] && a[i] < INPUT_A_MAX); /* 前提条件 */
  }
  /* 出力 a[input_n-1]から降順に出力 */
  cout << a[input_n - 1];
  for (int i = input_n - 2; i >= 0; i--) {
    cout << " " << a[i];
  }
  cout << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int h;
  int in;
  int a[100];
  int i;
  while (cin >> h) {
    for (i = 0; i < h; i++) {
      cin >> in;
      *(a + i) = in;
    }
    *(a + i) = '\\0';
    for (i = h - 1; i > 0; i--) {
      cout << a[i] << " ";
    }
    cout << a[0] << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int h;
  int in;
  int *a;
  int i;
  while (cin >> h) {
    for (i = 0; i < h; i++) {
      cin >> in;
      *(a + i) = in;
    }
    *(a + i) = '\\0';
    for (i = h - 1; i >= 0; i--) {
      cout << a[i] << " ";
    }
  }
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

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


Error: TLE

Fixed submission:

#include <stdio.h>

int main() {

  int n = 0;
  scanf("%d", &n);
  int a[n + 1];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i = 1; i--) {
    printf("%d ", a[i]);
  }
  printf("%d\\n", a[0]);
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int i, n;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  for (i = n - 1; i >= 0; --i) {
    if (i)
      printf("%d ", a[i]);
    else
      printf("%d\\n", a[i]);
  }
  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int i, n;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; ++i)
    scanf("%d", a[i]);
  for (i = n - 1; i >= 0; --i) {
    if (i)
      printf("%d ", a[i]);
    else
      printf("%d\\n", a[i]);
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int n;
int a[1000];
int b = 0;

int main() {
  cin >> n;
  for (; b < n;) {
    cin >> a[b];
    ++b;
  }
  int c = n - 1;
  for (; 0 <= c;) {
    cout << a[c];
    if (0 < c) {
      cout << " ";
    }
    --c;
  }
  cout << endl;
}

Error: -11

Fixed submission:

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

int n;
int a[1000];
int b = 0;
int c = 0;

int main() {
  cin >> n;
  for (; b < n;) {
    cin >> a[b];
    ++b;
  }
  sort(a + b, a);
  for (; c < n;) {
    cout << a[c];
    ++c;
    if (c < n) {
      cout << " ";
    }
  }
  cout << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int main() {
  int n, i, *A;
  std::cin >> n;
  A = new int[n];
  for (i = n - 1; i >= 0; i--)
    std::cin >> A[i];
  for (i = 0; i < n; i++)
    std::cout << A[i] << (n - 1 == i ? "\\n" : " ");
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int n, i, *A;
  std::cin >> n;
  A = new int[n];
  for (i = n - 1; i >= 0; i++)
    std::cin >> A[i];
  for (i = 0; i < n; i++)
    std::cout << A[i] << (n % i == 1 ? "\\n" : " ");
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <vector>
int n;
std::vector<int> data;
void proc() {
  auto end = data.rend();
  for (auto it = data.rbegin(); it != end;) {
    printf("%d", *it);
    if (++it != end)
      printf(" ");
  }
  printf("\\n");
}

void input() {
  int x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    data.push_back(x);
  }
}

int main() {
  input();
  proc();
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <vector>
int n;
std::vector<int> data;
void proc() {
  auto begin = data.rbegin();
  for (auto it = data.rend(); it != begin;) {
    printf("%d", *it);
    if (++it != begin)
      printf(" ");
  }
  printf("\\n");
}

void input() {
  int x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    data.push_back(x);
  }
}

int main() {
  input();
  proc();
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i > 0; i--) {
    printf("%d ", a[i]);
  }
  cout << a[0] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n % 2 == 0) {
    for (int i = 0; i < n / 2; i++) {
      swap(a[i], a[n - 1 - i]);
    }
  } else {
    for (int i = 0; i < (n - 1) / 2; i++) {
      swap(a[i], a[n - 1 - i]);
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  return 0;
}