Problem p03315 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define start_routine                                                          \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  int begtime = clock();
#define end_routine                                                            \
  int endtime = clock();                                                       \
  cerr << endl                                                                 \
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \
       << " ms";                                                               \
  return 0
#define PB push_back
#define MP make_pair
#define MOD (int)1e9 + 7
#define int long long
#define maxn 100000
#define inf (int)3e18
#define eps (double)1e-8
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mii map<int, int>
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

vi f(maxn + 1, 0);
vi tree(4 * maxn + 1, 0);
vi arr(maxn + 1);

void add(int idx, int val) {
  while (idx <= maxn) {
    f[idx] += val;
    idx += idx & -idx;
  }
}

int query(int idx) {
  int ans = 0;
  while (idx > 0) {
    ans += f[idx];
    idx -= idx & -idx;
  }
  return ans;
}

void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = arr[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * node + 1, l, mid);
  build(2 * node + 2, mid + 1, r);
  tree[node] = max(tree[2 * node + 2], tree[2 * node + 1]);
}

int find_max(int node, int l, int r, int lq, int rq) {
  if (l == r && lq <= l && l <= rq)
    return tree[node];
  if (l > rq || r < lq)
    return -1;
  if (l >= lq && r <= rq)
    return tree[node];
  int mid = (l + r) >> 1;
  return max(find_max(2 * node + 1, l, mid, lq, rq),
             find_max(2 * node + 2, mid + 1, r, lq, rq));
}

signed main() {
  start_routine;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  string s;
  cin >> s;

  int a = 0;
  for (int i = 0; i < len(s); ++i) {
    if (s[i] == '+')
      a += 1;
    else if (s[i] == '-')
      a -= 1;
  }
  print(a);
  end_routine;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define start_routine                                                          \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  int begtime = clock();
#define end_routine                                                            \
  int endtime = clock();                                                       \
  cerr << endl                                                                 \
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \
       << " ms";                                                               \
  return 0
#define PB push_back
#define MP make_pair
#define MOD (int)1e9 + 7
#define int long long
#define maxn 100000
#define inf (int)3e18
#define eps (double)1e-8
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mii map<int, int>
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

vi f(maxn + 1, 0);
vi tree(4 * maxn + 1, 0);
vi arr(maxn + 1);

void add(int idx, int val) {
  while (idx <= maxn) {
    f[idx] += val;
    idx += idx & -idx;
  }
}

int query(int idx) {
  int ans = 0;
  while (idx > 0) {
    ans += f[idx];
    idx -= idx & -idx;
  }
  return ans;
}

void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = arr[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * node + 1, l, mid);
  build(2 * node + 2, mid + 1, r);
  tree[node] = max(tree[2 * node + 2], tree[2 * node + 1]);
}

int find_max(int node, int l, int r, int lq, int rq) {
  if (l == r && lq <= l && l <= rq)
    return tree[node];
  if (l > rq || r < lq)
    return -1;
  if (l >= lq && r <= rq)
    return tree[node];
  int mid = (l + r) >> 1;
  return max(find_max(2 * node + 1, l, mid, lq, rq),
             find_max(2 * node + 2, mid + 1, r, lq, rq));
}

signed main() {
  start_routine;
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif

  string s;
  cin >> s;

  int a = 0;
  for (int i = 0; i < len(s); ++i) {
    if (s[i] == '+')
      a += 1;
    else if (s[i] == '-')
      a -= 1;
  }
  print(a);
  end_routine;
}