Problem p03209 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define vecp(p)                                                                \
  int aa;                                                                      \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecpl(p)                                                               \
  long long aa;                                                                \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecps(p)                                                               \
  string aa;                                                                   \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecp2(p)                                                               \
  int ab;                                                                      \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define vecpl2(p)                                                              \
  long long ab;                                                                \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define vecps2(p)                                                              \
  string ab;                                                                   \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define set0(k, n)                                                             \
  for (int nn = 0; nn < (n); nn++) {                                           \
    (k).push_back(0);                                                          \
  }
#define sorts(c) sort((c).begin(), (c).end());
#define reverses(c) reverse((c).begin(), (c).end());
#define vec(b) vector<int>(b);
#define vecl(b) vector<long long>(b);
#define vecs(b) vector<string>(b);
#define vecsize(b, size) vector<int>(b)((size));
#define pb(b, a) (b).push_back((a));
#define doublece(a, b) cout << (a) << ' ' << (b) << endl;
#define pairs(s) vector<pair<int, int>>(s);
#define pairsl(s) vector<pair<ll, ll>>(s);
#define pairss(s) vector<pair<string, string>>(s);
#define pairsp(s)                                                              \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairspl(s)                                                             \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairsps(s)                                                             \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairsREV(s) (s).push_back(make_pair(bb, aa));
#define pairslREV(s) (s).push_back(make_pair(bb, aa));
#define pairssREV(s) (s).push_back(make_pair(bb, aa));
#define MOD 1000000007
vecl(A) vecl(B)

    ll ref(int n, ll x) {
  if (x <= 1) {
    if (n == 0)
      return 1;
    else
      return 0;
  }
  if (A.at(n - 1) + 2 > x) {
    return ref(n - 1, x - 1);
  }
  if (A.at(n - 1) + 2 == x) {
    return (B.at(n - 1) + 1);
  }
  if (A.at(n - 1) + 2 < x) {
    return (B.at(n - 1) + 1 + ref(n - 1, x - A.at(n - 1) - 2));
  }
}

int main() {

  int N;
  ll X;
  cin >> N >> X;
  pb(A, 1) pb(B, 1)
      fx(N + 1){pb(A, A.at(x) * 2 + 3) pb(B, B.at(x) * 2 + 1)} ll ans = 0;
  ans = ref(N, X);
  ce(ans)
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define vecp(p)                                                                \
  int aa;                                                                      \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecpl(p)                                                               \
  long long aa;                                                                \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecps(p)                                                               \
  string aa;                                                                   \
  cin >> aa;                                                                   \
  (p).push_back(aa);
#define vecp2(p)                                                               \
  int ab;                                                                      \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define vecpl2(p)                                                              \
  long long ab;                                                                \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define vecps2(p)                                                              \
  string ab;                                                                   \
  cin >> ab;                                                                   \
  (p).push_back(ab);
#define set0(k, n)                                                             \
  for (int nn = 0; nn < (n); nn++) {                                           \
    (k).push_back(0);                                                          \
  }
#define sorts(c) sort((c).begin(), (c).end());
#define reverses(c) reverse((c).begin(), (c).end());
#define vec(b) vector<int>(b);
#define vecl(b) vector<long long>(b);
#define vecs(b) vector<string>(b);
#define vecsize(b, size) vector<int>(b)((size));
#define pb(b, a) (b).push_back((a));
#define doublece(a, b) cout << (a) << ' ' << (b) << endl;
#define pairs(s) vector<pair<int, int>>(s);
#define pairsl(s) vector<pair<ll, ll>>(s);
#define pairss(s) vector<pair<string, string>>(s);
#define pairsp(s)                                                              \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairspl(s)                                                             \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairsps(s)                                                             \
  int aa, bb;                                                                  \
  cin >> aa >> bb;                                                             \
  (s).push_back(make_pair(aa, bb));
#define pairsREV(s) (s).push_back(make_pair(bb, aa));
#define pairslREV(s) (s).push_back(make_pair(bb, aa));
#define pairssREV(s) (s).push_back(make_pair(bb, aa));
#define MOD 1000000007
vecl(A) vecl(B)

    ll ref(int n, ll x) {
  if (x <= 1 || n == 0) {
    if (n == 0)
      return 1;
    else
      return 0;
  }
  if (A.at(n - 1) + 2 > x) {
    return ref(n - 1, x - 1);
  }
  if (A.at(n - 1) + 2 == x) {
    return (B.at(n - 1) + 1);
  }
  if (A.at(n - 1) + 2 < x) {
    return (B.at(n - 1) + 1 + ref(n - 1, x - A.at(n - 1) - 2));
  }
}

int main() {

  int N;
  ll X;
  cin >> N >> X;
  pb(A, 1) pb(B, 1)
      fx(N + 1){pb(A, A.at(x) * 2 + 3) pb(B, B.at(x) * 2 + 1)} ll ans = 0;
  ans = ref(N, X);
  ce(ans)
}