Problem p03425 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  // {M,A,R,C,H} -> {0,1,2,3,4}
  vll c(5);
  rep(i, n) {
    if (s[i][0] == 'M')
      c[0]++;
    else if (s[i][0] == 'A')
      c[1]++;
    else if (s[i][0] == 'R')
      c[2]++;
    else if (s[i][0] == 'C')
      c[3]++;
    else if (s[i][0] == 'H')
      c[4]++;
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  // {M,A,R,C,H} -> {0,1,2,3,4}
  vll c(5);
  rep(i, n) {
    if (s[i][0] == 'M')
      c[0]++;
    else if (s[i][0] == 'A')
      c[1]++;
    else if (s[i][0] == 'R')
      c[2]++;
    else if (s[i][0] == 'C')
      c[3]++;
    else if (s[i][0] == 'H')
      c[4]++;
  }

  ll ans = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i + 1; j < 5; ++j) {
      for (int k = j + 1; k < 5; ++k) {
        ans += c[i] * c[j] * c[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}