Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
// #define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 100050;
// ↑templete
int main() {
  string S;
  cin >> S;
  int N = S.length();
  ll A[SIZE] = {}, B[SIZE] = {};

  int a = 0;
  for (int i = 0; i <= N; i++) {
    if (i == N) {
      A[i] = a;
      continue;
    }
    if (S[i] == '<') {
      A[i] = a;
      a++;
    } else {
      A[i] = a;
      a = 0;
    }
  }
  int b = 0;
  for (int i = N; i >= 0; i--) {
    if (i == 0) {
      B[i] = b;
      continue;
    }
    if (S[i - 1] == '>') {
      B[i] = b;
      b++;
    } else {
      B[i] = b;
      b = 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i <= N; i++)
    ans += max(A[i], B[i]);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
// #define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 500050;
// ↑templete
int main() {
  string S;
  cin >> S;
  int N = S.length();
  ll A[SIZE] = {}, B[SIZE] = {};

  int a = 0;
  for (int i = 0; i <= N; i++) {
    if (i == N) {
      A[i] = a;
      continue;
    }
    if (S[i] == '<') {
      A[i] = a;
      a++;
    } else {
      A[i] = a;
      a = 0;
    }
  }
  int b = 0;
  for (int i = N; i >= 0; i--) {
    if (i == 0) {
      B[i] = b;
      continue;
    }
    if (S[i - 1] == '>') {
      B[i] = b;
      b++;
    } else {
      B[i] = b;
      b = 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i <= N; i++)
    ans += max(A[i], B[i]);
  cout << ans << endl;
  return 0;
}