Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void print(vector<T> &V, bool spaced = true) {
  string space;
  spaced ? space = " " : space = "";
  for (int i = 0; i < V.size(); i++) {
    cout << V[i] << space;
  }
  cout << '\n';
}

template <class T> void printendl(vector<T> &V) {
  for (int i = 0; i < V.size(); i++) {
    cout << V[i] << '\n';
  }
}

template <class T> T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> T Max(T a, T b) { return (a < b) ? b : a; }

template <class T> T Min(T a, T b) { return (a < b) ? a : b; }

// str

bool isPalindrome(string str) {

  int length = str.length();

  for (int i = 0; i < (length / 2); i++)
    if (str[i] != str[length - 1 - i])
      return false;

  return true;
}

void reverseStr(string &str) {
  int n = str.length();
  for (int i = 0; i < n / 2; i++)
    swap(str[i], str[n - i - 1]);
}

// Read through the messages at the end when you're done

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;
  int l = s.length();
  vector<char> v;
  rep(i, 0, l) {
    if (s[i] != 'B') {
      v.pb(s[i]);
    } else {
      v.pop_back();
    }
  }

  print(v, false);

  return 0;
}

// Use long long da5eel rabbak!
// Dont use endl;
// DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
// Dear Amine, just because it worked for the test cases doesnt necessarily mean
// it is correct. Dear Amine, try it on ur own test cases iza ur not SURE In
// case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS DONT FORGET TO MOD
// EVERYTHING IZA U NEED TO MOD


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void print(vector<T> &V, bool spaced = true) {
  string space;
  spaced ? space = " " : space = "";
  for (int i = 0; i < V.size(); i++) {
    cout << V[i] << space;
  }
  cout << '\n';
}

template <class T> void printendl(vector<T> &V) {
  for (int i = 0; i < V.size(); i++) {
    cout << V[i] << '\n';
  }
}

template <class T> T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> T Max(T a, T b) { return (a < b) ? b : a; }

template <class T> T Min(T a, T b) { return (a < b) ? a : b; }

// str

bool isPalindrome(string str) {

  int length = str.length();

  for (int i = 0; i < (length / 2); i++)
    if (str[i] != str[length - 1 - i])
      return false;

  return true;
}

void reverseStr(string &str) {
  int n = str.length();
  for (int i = 0; i < n / 2; i++)
    swap(str[i], str[n - i - 1]);
}

// Read through the messages at the end when you're done

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;
  int l = s.length();
  vector<char> v;
  rep(i, 0, l) {
    if (s[i] != 'B') {
      v.pb(s[i]);
    } else if (v.size() > 0) {
      v.pop_back();
    }
  }

  print(v, false);

  return 0;
}

// Use long long da5eel rabbak!
// Dont use endl;
// DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
// Dear Amine, just because it worked for the test cases doesnt necessarily mean
// it is correct. Dear Amine, try it on ur own test cases iza ur not SURE In
// case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS DONT FORGET TO MOD
// EVERYTHING IZA U NEED TO MOD