Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937
    rng(chrono::steady_clock::now()
            .time_since_epoch()
            .count()); // can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) {
  return (rng() % (y + 1 - x)) + x;
} // inclusivesss
string inline to_string(char c) {
  string s(1, c);
  return s;
}
template <typename T> inline T gcd(T a, T b) {
  return a == 0 ? b : gcd(b % a, a);
}

#define ll long long int
#define ld long double
#define FOR(ii, ss, ee) for (ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for (ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> spi;
typedef pair<pi, pi> dpi;

#define LLINF ((long long)1e18) // 1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (500003)
int main() {
  FAST string s;
  cin >> s;
  vector<pair<ll, char>> v;
  FOR(i, 0, s.size() - 1) {
    if (v.empty())
      v.eb(1, s[i]);
    else if (s[i] == s[i - 1])
      ++v.back().f;
    else
      v.eb(1, s[i]);
  }
  ll ans = 0;
  FOR(i, 1, siz(v) - 1) if (v[i - 1].s == '<' && v[i].s == '>') {
    ans += v[i - 1].f * (v[i - 1].f - 1) / 2;
    ans += v[i].f * (v[i].f - 1) / 2;
    ans += max(v[i].f, v[i - 1].f);
  }
  if (v.size() & 1)
    assert(0), ans += v.back().f * (v.back().f + 1) / 2;
  if (v.size() > 1 && v[0].s == '>')
    assert(0), ans += v[0].f * (v[0].f + 1) / 2;
  cout << ans << '\n';
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;

#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937
    rng(chrono::steady_clock::now()
            .time_since_epoch()
            .count()); // can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) {
  return (rng() % (y + 1 - x)) + x;
} // inclusivesss
string inline to_string(char c) {
  string s(1, c);
  return s;
}
template <typename T> inline T gcd(T a, T b) {
  return a == 0 ? b : gcd(b % a, a);
}

#define ll long long int
#define ld long double
#define FOR(ii, ss, ee) for (ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for (ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> spi;
typedef pair<pi, pi> dpi;

#define LLINF ((long long)1e18) // 1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (500003)
int main() {
  FAST string s;
  cin >> s;
  vector<pair<ll, char>> v;
  FOR(i, 0, s.size() - 1) {
    if (v.empty())
      v.eb(1, s[i]);
    else if (s[i] == s[i - 1])
      ++v.back().f;
    else
      v.eb(1, s[i]);
  }
  ll ans = 0;
  FOR(i, 1, siz(v) - 1) if (v[i - 1].s == '<' && v[i].s == '>') {
    ans += v[i - 1].f * (v[i - 1].f - 1) / 2;
    ans += v[i].f * (v[i].f - 1) / 2;
    ans += max(v[i].f, v[i - 1].f);
  }
  if (v.back().s == '<')
    ans += v.back().f * (v.back().f + 1) / 2;
  if (v[0].s == '>')
    ans += v[0].f * (v[0].f + 1) / 2;
  cout << ans << '\n';
}