Problem p03618 (C++)

Buggy submission (status: Runtime Error):
#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#pragma comment(linker, "/STACK:167772160")

using namespace std;
#define mp make_pair
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " : " << (x) << endl
#define print_array(arr, len)                                                  \
  {                                                                            \
    cerr << #arr << " : ";                                                     \
    for (int i = 0; i < len; ++i)                                              \
      cerr << arr[i] << ' ';                                                   \
    cerr << endl;                                                              \
  }
#define print_2d_array(arr, len1, len2)                                        \
  {                                                                            \
    cerr << #arr << endl;                                                      \
    for (int i = 0; i < len1; ++i, cerr << endl)                               \
      for (int j = 0; j < len2; ++j)                                           \
        cerr << arr[i][j] << ' ';                                              \
  }
#define print_iterable(i)                                                      \
  {                                                                            \
    cerr << #i << " : ";                                                       \
    for (auto e : i)                                                           \
      cerr << e << ' ';                                                        \
    cerr << endl;                                                              \
  }
#define print_new_line() cerr << endl

template <typename T, typename Q> void print_pair1(pair<T, Q> x) {
  cerr << "(" << x.first << ", " << x.second << ")\n";
}

#define print_pair(x)                                                          \
  {                                                                            \
    cerr << #x << " : ";                                                       \
    print_pair1(x);                                                            \
  }
#else
#define print_pair(x) (void)0
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len)                                                  \
  {}
#define print_2d_array(arr, len1, len2)                                        \
  {}
#define print_iterable(i)                                                      \
  {}
#define print_new_line() (void)0
#endif

#define rand govno_ebanoe

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const ld EPS = 1e-12;
#pragma endregion

#ifdef LOCAL
#define ERR_CATCH
// #define NOERR
#endif

const int N = 1e5 + 10;
ll n;
char s[N];
ll cnt[N];

void solve() {
  scanf("%s", s);
  n = strlen(s);
  ll ans = (n - 1) * n / 2 + 1;
  for (int i = 0; i < n; ++i)
    ++cnt[s[i]];
  for (int i = 0; i < N; ++i)
    ans -= cnt[i] * (cnt[i] - 1) / 2;
  printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#ifdef NOERR
  freopen("err.txt", "w", stderr);
#endif
#else
  // freopen("knight.in", "r", stdin);
  // freopen("knight.out", "w", stdout);
#endif

#ifdef ERR_CATCH
  try {
#endif

#ifdef ST
    while (true)
      solve();
#endif
#ifdef CASES
#define MULTITEST
#endif
#ifdef MULTITEST
    int t;
    scanf("%d", &t);
    char endl1[5];
    fgets(endl1, 5, stdin);
    for (int i = 0; i < t; ++i) {
#ifdef CASES
      printf("Case #%d: ", i + 1);
#endif
      solve();
#ifdef CASES
      eprintf("Passed case #%d:\n", i + 1);
#endif
    }
#else
  solve();
#endif

#ifdef ERR_CATCH
  } catch (logic_error e) {
    print_var(e.what());
    puts("_____________________________________________________________________"
         "______");
    exit(0);
  }
#endif
#ifdef LOCAL
  eprintf("\n\nTime: %.3lf\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}

Fixed submission:
#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#pragma comment(linker, "/STACK:167772160")

using namespace std;
#define mp make_pair
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " : " << (x) << endl
#define print_array(arr, len)                                                  \
  {                                                                            \
    cerr << #arr << " : ";                                                     \
    for (int i = 0; i < len; ++i)                                              \
      cerr << arr[i] << ' ';                                                   \
    cerr << endl;                                                              \
  }
#define print_2d_array(arr, len1, len2)                                        \
  {                                                                            \
    cerr << #arr << endl;                                                      \
    for (int i = 0; i < len1; ++i, cerr << endl)                               \
      for (int j = 0; j < len2; ++j)                                           \
        cerr << arr[i][j] << ' ';                                              \
  }
#define print_iterable(i)                                                      \
  {                                                                            \
    cerr << #i << " : ";                                                       \
    for (auto e : i)                                                           \
      cerr << e << ' ';                                                        \
    cerr << endl;                                                              \
  }
#define print_new_line() cerr << endl

template <typename T, typename Q> void print_pair1(pair<T, Q> x) {
  cerr << "(" << x.first << ", " << x.second << ")\n";
}

#define print_pair(x)                                                          \
  {                                                                            \
    cerr << #x << " : ";                                                       \
    print_pair1(x);                                                            \
  }
#else
#define print_pair(x) (void)0
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len)                                                  \
  {}
#define print_2d_array(arr, len1, len2)                                        \
  {}
#define print_iterable(i)                                                      \
  {}
#define print_new_line() (void)0
#endif

#define rand govno_ebanoe

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int INF = (int)1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const ld EPS = 1e-12;
#pragma endregion

#ifdef LOCAL
#define ERR_CATCH
// #define NOERR
#endif

const int N = 2e5 + 10;
ll n;
char s[N];
ll cnt[N];

void solve() {
  scanf("%s", s);
  n = strlen(s);
  ll ans = (n - 1) * n / 2 + 1;
  for (int i = 0; i < n; ++i)
    ++cnt[s[i]];
  for (int i = 0; i < N; ++i)
    ans -= cnt[i] * (cnt[i] - 1) / 2;
  printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#ifdef NOERR
  freopen("err.txt", "w", stderr);
#endif
#else
  // freopen("knight.in", "r", stdin);
  // freopen("knight.out", "w", stdout);
#endif

#ifdef ERR_CATCH
  try {
#endif

#ifdef ST
    while (true)
      solve();
#endif
#ifdef CASES
#define MULTITEST
#endif
#ifdef MULTITEST
    int t;
    scanf("%d", &t);
    char endl1[5];
    fgets(endl1, 5, stdin);
    for (int i = 0; i < t; ++i) {
#ifdef CASES
      printf("Case #%d: ", i + 1);
#endif
      solve();
#ifdef CASES
      eprintf("Passed case #%d:\n", i + 1);
#endif
    }
#else
  solve();
#endif

#ifdef ERR_CATCH
  } catch (logic_error e) {
    print_var(e.what());
    puts("_____________________________________________________________________"
         "______");
    exit(0);
  }
#endif
#ifdef LOCAL
  eprintf("\n\nTime: %.3lf\n", double(clock()) / CLOCKS_PER_SEC);
#endif
}