Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = n - 1; i >= (int)0; i--)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> name(n);                                                   \
  rep(i, n) std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a)));
#define vvvvector(name, t, k, l, m, n, a)                                      \
  vector<vector<vector<vector<t>>>> name(                                      \
      k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a))));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main() {
  string s;
  std::cin >> s;
  int n = s.size();
  ll ans = 0ll;
  for (int bit = 0; bit < (1 << n - 1); bit++) {
    /* code */
    std::vector<string> d(1);
    d[0] += s[0];
    rep(i, n - 1) {
      if (bit & (1 << i))
        d.pb(string(1, s[i + 1]));
      else
        d[d.size() - 1] = d[d.size() - 1] + s[i + 1];
    }
    // rep(i,d.size())std::cout << d[i] << std::endl;
    rep(i, d.size()) ans += stoi(d[i]);
  }
  std::cout << ans << std::endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = n - 1; i >= (int)0; i--)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n)                                                     \
  std::vector<type> name(n);                                                   \
  rep(i, n) std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a)                                            \
  vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a)                                          \
  vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a)));
#define vvvvector(name, t, k, l, m, n, a)                                      \
  vector<vector<vector<vector<t>>>> name(                                      \
      k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a))));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main() {
  string s;
  std::cin >> s;
  int n = s.size();
  ll ans = 0ll;
  for (int bit = 0; bit < (1 << n - 1); bit++) {
    /* code */
    std::vector<string> d(1);
    d[0] += s[0];
    rep(i, n - 1) {
      if (bit & (1 << i))
        d.pb(string(1, s[i + 1]));
      else
        d[d.size() - 1] = d[d.size() - 1] + s[i + 1];
    }
    // rep(i,d.size())std::cout << d[i] << std::endl;
    rep(i, d.size()) ans += stoll(d[i]);
  }
  std::cout << ans << std::endl;
}