Problem p03394 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (long long i = 0; i < (ll)m; i++)
#define FOR(i, n, m) for (long long i = n; i < (ll)m; i++)
#define DUMP(a)                                                                \
  for (long long dump = 0; dump < (ll)a.size(); dump++) {                      \
    cout << a[dump];                                                           \
    if (dump != (ll)a.size() - 1)                                              \
      cout << " ";                                                             \
    else                                                                       \
      cout << endl;                                                            \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v)                                                              \
  sort(v.begin(), v.end());                                                    \
  v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> ans;
  if (n == 3) {
    cout << 2 << " " << 5 << " " << 63 << endl;
    return 0;
  }
  ans.pb(2);
  ans.pb(4);
  ans.pb(3);
  ans.pb(9);
  n -= 4;
  ll c = 8;
  while (n > 1 && c <= 29996) {
    ans.pb(c);
    ans.pb(c + 2);
    c += 6;
    n -= 2;
  }
  c = 15;
  while (n > 1 && c <= 29991) {
    ans.pb(c);
    ans.pb(c + 6);
    c += 12;
    n -= 2;
  }
  c = 6;
  while (n > 0) {
    ans.pb(c);
    c += 6;
  }
  sort(ALL(ans));
  DUMP(ans);
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (long long i = 0; i < (ll)m; i++)
#define FOR(i, n, m) for (long long i = n; i < (ll)m; i++)
#define DUMP(a)                                                                \
  for (long long dump = 0; dump < (ll)a.size(); dump++) {                      \
    cout << a[dump];                                                           \
    if (dump != (ll)a.size() - 1)                                              \
      cout << " ";                                                             \
    else                                                                       \
      cout << endl;                                                            \
  }
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v)                                                              \
  sort(v.begin(), v.end());                                                    \
  v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> ans;
  if (n == 3) {
    cout << 2 << " " << 5 << " " << 63 << endl;
    return 0;
  }
  ans.pb(2);
  ans.pb(4);
  ans.pb(3);
  ans.pb(9);
  n -= 4;
  ll c = 8;
  while (n > 1 && c <= 29996) {
    ans.pb(c);
    ans.pb(c + 2);
    c += 6;
    n -= 2;
  }
  c = 15;
  while (n > 1 && c <= 29991) {
    ans.pb(c);
    ans.pb(c + 6);
    c += 12;
    n -= 2;
  }
  c = 6;
  while (n > 0) {
    ans.pb(c);
    c += 6;
    n--;
  }
  sort(ALL(ans));
  DUMP(ans);
}