Language: C++

#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;

vector<pair<char, ll>> prs;

int main(void) {
  // Here your code !
  cin >> s;

  int n = s.size() + 1;

  vector<ll> base(n, -1L);

  if (s[0] == '<') base[0] = 0;

  if (s.back() == '>') base[n - 1] = 0;

  for (int i = 1; i < s.size(); ++i) {
    if (s[i - 1] == '>' && s[i] == '<') {
      base[i] = 0;
    }
  }

  s.insert(0, s[0] == '<' ? "_" : ">");

  // for (auto &e : s) {
  //   printf("%2c ", e);
  // }
  // printf("\n");

  // for (auto &e : base) {
  //   printf("%2d ", e);
  // }
  // printf("\n");

  for (int i = 0; i < n; ++i) {
    if (base[i] != 0) continue;

    for (int j = i + 1; j < n; ++j) {
      if (base[j] == 0) break;
      if (s[j] == '>') break;
      base[j] = max(base[j], j - i);
    }

    for (int j = i - 1; j >= 0; --j) {
      if (base[j] == 0) break;
      if (s[j] == '<') break;
      base[j] = max(base[j], i - j);
    }
  }

  // for (auto &e : s) {
  //   printf("%2c ", e);
  // }
  // printf("\n");

  // for (auto &e : base) {
  //   printf("%2d ", e);
  // }
  // printf("\n");

  for (int i = 0; i < n; ++i) {
    if (s[i] == '<' && s[i + 1] == '>') {
      if (base[i] <= base[i + 1]) base[i] = base[i + 1] + 1;
    }
  }

  // for (auto &e : s) {
  //   printf("%2c ", e);
  // }
  // printf("\n");

  // for (auto &e : base) {
  //   printf("%2d ", e);
  // }
  // printf("\n");

  ll ans = 0;

  for (auto &e : base) {
    ans += e;
  }

  printf("%lld\n", ans);

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:20: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int)'
   49 |       base[j] = max(base[j], j - i);
      |                 ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:49:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   49 |       base[j] = max(base[j], j - i);
      |                 ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:49:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   49 |       base[j] = max(base[j], j - i);
      |                 ~~~^~~~~~~~~~~~~~~~
a.cc:55:20: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int)'
   55 |       base[j] = max(base[j], i - j);
      |                 ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:55:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   55 |       base[j] = max(base[j], i - j);
      |                 ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:55:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   55 |       base[j] = max(base[j], i - j);
      |                 ~~~^~~~~~~~~~~~~~~~