Problem p02726 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \\
  type a;                                                                      \\
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl

int main() {
  int ajapa;
  IN(int, n);
  IN(int, x);
  IN(int, y);
  vi ans(n, 0);
  REPS(i, n - 1) {
    if (i <= x) {
      for (int j = i; j < y; j++) {
        ajapa = min(j - i, y - j + x - i + 1);
        ans[ajapa]++;
      }
      for (int j = y; j <= n; j++) {
        ans[x - i + j - y + 1]++;
      }
    } else if (i < y) {
      for (int j = i; j < y; j++) {
        ajapa = min(j - i, y - j + i - x + 1);
        ans[ajapa]++;
      }
      for (int j = y; j <= n; j++) {

        ajapa = min(j - i, j - y + i - x + 1);
        ans[ajapa]++;
      }
    } else {
      for (int j = i + 1; j <= n; j++) {
        ans[j - i]++;
      }
    }
  }

  REPS(i, n - 1) { COUT(ans[i]); }
  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define ALL(x) (x).begin(), (x).end()
#define IN(type, a)                                                            \\
  type a;                                                                      \\
  cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl

int main() {
  int ajapa;
  IN(int, n);
  IN(int, x);
  IN(int, y);
  vi ans(n, 0);
  REPS(i, n - 1) {
    if (i <= x) {
      for (int j = i; j < y; j++) {
        ajapa = min(j - i, y - j + x - i + 1);
        ans[ajapa]++;
      }
      for (int j = y; j <= n; j++) {
        ans[x - i + j - y + 1]++;
      }
    } else if (i < y) {
      for (int j = i; j < y; j++) {
        ans[j - i]++;
      }
      for (int j = y; j <= n; j++) {
        ajapa = min(j - i, j - y + i - x + 1);
        ans[ajapa]++;
      }
    } else {
      REPS(j, n) { ans[j - i]++; }
    }
  }

  REPS(i, n - 1) { COUT(ans[i]); }
  return 0;
}