Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for (ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const ll MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, x;
  cin >> N >> x;
  if (N == 2) {
    if (x == 2) {
      cout << "Yes"
           << "\n";
      rep(i, 0, 3) { cout << i + 1 << "\n"; }
    } else
      cout << "No"
           << "\n";
  }
  if (x >= 2 && x <= 2 * N - 2) {
    cout << "Yes"
         << "\n";
    vector<int> ans(2 * N - 1, 0);
    set<int> s;
    if (x != 2 * N - 2) {
      ans[N - 3] = x + 1;
      ans[N - 2] = 1;
      ans[N - 1] = x;
      ans[N] = x + 2;
      rep(i, 1, 2 * N) {
        if (i != 1 && i != x && i != x + 1 && i != x + 2)
          s.insert(i);
      }
      int cnt = 0;
      for (auto d : s) {
        if (cnt < N - 3)
          ans[cnt] = d;
        else
          ans[cnt + 4] = d;
        cnt++;
      }
    } else {
      ans[N - 3] = x - 1;
      ans[N - 2] = 2 * N - 1;
      ans[N - 1] = x;
      ans[N] = x - 2;
      rep(i, 1, 2 * N) {
        if (i != 2 * N - 1 && i != x && i != x - 1 && i != x - 2)
          s.insert(i);
      }
      int cnt = 0;
      for (auto d : s) {
        if (cnt < N - 3)
          ans[cnt] = d;
        else
          ans[cnt + 4] = d;
        cnt++;
      }
    }
    rep(i, 0, 2 * N - 1) { cout << ans[i] << "\n"; }
  } else {
    cout << "No"
         << "\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for (ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const ll MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, x;
  cin >> N >> x;
  if (N == 2) {
    if (x == 2) {
      cout << "Yes"
           << "\n";
      rep(i, 0, 3) { cout << i + 1 << "\n"; }
    } else
      cout << "No"
           << "\n";
  } else if (x >= 2 && x <= 2 * N - 2) {
    cout << "Yes"
         << "\n";
    vector<int> ans(2 * N - 1, 0);
    set<int> s;
    if (x != 2 * N - 2) {
      ans[N - 3] = x + 1;
      ans[N - 2] = 1;
      ans[N - 1] = x;
      ans[N] = x + 2;
      rep(i, 1, 2 * N) {
        if (i != 1 && i != x && i != x + 1 && i != x + 2)
          s.insert(i);
      }
      int cnt = 0;
      for (auto d : s) {
        if (cnt < N - 3)
          ans[cnt] = d;
        else
          ans[cnt + 4] = d;
        cnt++;
      }
    } else {
      ans[N - 3] = x - 1;
      ans[N - 2] = 2 * N - 1;
      ans[N - 1] = x;
      ans[N] = x - 2;
      rep(i, 1, 2 * N) {
        if (i != 2 * N - 1 && i != x && i != x - 1 && i != x - 2)
          s.insert(i);
      }
      int cnt = 0;
      for (auto d : s) {
        if (cnt < N - 3)
          ans[cnt] = d;
        else
          ans[cnt + 4] = d;
        cnt++;
      }
    }
    rep(i, 0, 2 * N - 1) { cout << ans[i] << "\n"; }
  } else {
    cout << "No"
         << "\n";
  }
}