prithivMLmods/Coder-Stat huggingface dataset:
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
///------------------  ONESHOTAC -------------------
#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i++)
#define FORD(i, j, k) for (int i = j; i >= k; i--)
#define mp make_pair
// #define f first
// #define s second
// #define int long long
using namespace std;

const int MOD = 1e9 + 7;
const int N = 200005;
int n;
int res[N];
string s;
int d[N];
vector<int> ke[N];
long long sum = 0;
void BFS() {
  queue<int> qu;
  FOR(i, 1, n) {
    if (d[i] == 0) {
      qu.push(i);
    }
  }
  while (qu.size()) {
    int u = qu.front();
    qu.pop();
    for (int v : ke[u]) {
      d[v]--;
      if (d[v] == 0) {
        res[v] = res[u] + 1;
        qu.push(v);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //    freopen("AGC040.inp","r",stdin);
  //    freopen("AGC040.out","w",stdout);
  cin >> s;
  s = ' ' + s;
  n = s.size();
  FOR(i, 1, n - 1) {
    if (s[i] == '>') {
      //            ke[i].push_back(i + 1);
      d[i]++;
      ke[i + 1].push_back(i);
    } else {
      //            ke[i + 1].push_back(i);
      d[i + 1]++;
      ke[i].push_back(i + 1);
    }
  }
  BFS();
  FOR(i, 1, n) sum += res[i];
  cout << sum;
  return 0;
}


Fixed submission:
///------------------  ONESHOTAC -------------------
#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i++)
#define FORD(i, j, k) for (int i = j; i >= k; i--)
#define mp make_pair
// #define f first
// #define s second
// #define int long long
using namespace std;

const int MOD = 1e9 + 7;
const int N = 500005;
int n;
int res[N];
string s;
int d[N];
vector<int> ke[N];
long long sum = 0;
void BFS() {
  queue<int> qu;
  FOR(i, 1, n) {
    if (d[i] == 0) {
      qu.push(i);
    }
  }
  while (qu.size()) {
    int u = qu.front();
    qu.pop();
    for (int v : ke[u]) {
      d[v]--;
      if (d[v] == 0) {
        res[v] = res[u] + 1;
        qu.push(v);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //    freopen("AGC040.inp","r",stdin);
  //    freopen("AGC040.out","w",stdout);
  cin >> s;
  s = ' ' + s;
  n = s.size();
  FOR(i, 1, n - 1) {
    if (s[i] == '>') {
      //            ke[i].push_back(i + 1);
      d[i]++;
      ke[i + 1].push_back(i);
    } else {
      //            ke[i + 1].push_back(i);
      d[i + 1]++;
      ke[i].push_back(i + 1);
    }
  }
  BFS();
  FOR(i, 1, n) sum += res[i];
  cout << sum;
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  char S[1000000];
  cin >> S;

  vector<int> vec;

  for (int i = 0; S[i] != '\0';) {
    if (S[i] == '<') {
      int n = 0;
      // vec.push_back(n);
      while (S[i] == '<') {
        n++;
        vec.push_back(n);
        i++;
      }
    } else {
      int n = 0;
      while (S[i] == '>') {
        n++;
        i++;
      }

      if (vec[vec.size() - 1] < n) {
        vec[vec.size() - 1] = n;
      }
      n--;
      while (n >= 0) {
        vec.push_back(n);
        n--;
      }
    }
  }

  long long sum = 0;

  for (int i = 0; i < vec.size(); i++) {
    sum += vec[i];
    // cout << vec[i] << " ";
  }
  // cout << endl;

  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  char S[1000000];
  cin >> S;

  vector<int> vec;

  for (int i = 0; S[i] != '\0';) {
    if (S[i] == '<') {
      int n = 0;
      // vec.push_back(n);
      while (S[i] == '<') {
        n++;
        vec.push_back(n);
        i++;
      }
    } else {
      int n = 0;
      while (S[i] == '>') {
        n++;
        i++;
      }

      if (vec.size() != 0) {
        if (vec[vec.size() - 1] < n) {
          vec[vec.size() - 1] = n;
        }
      } else {
        vec.push_back(n);
      }
      n--;
      while (n >= 0) {
        vec.push_back(n);
        n--;
      }
    }
  }

  long long sum = 0;

  for (int i = 0; i < vec.size(); i++) {
    sum += vec[i];
    // cout << vec[i] << " ";
  }
  // cout << endl;

  cout << sum << endl;
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 2e5 + 10;
char c[maxn];
int len, head[maxn], num;
struct Le {
  int nt, to;
} edge[maxn << 1];
bool vis[maxn];
int M[maxn];
void dfs(int u, int dis) {
  M[u] = max(M[u], dis);
  for (int i = head[u]; i; i = edge[i].nt) {
    int v = edge[i].to;
    dfs(v, dis + 1);
  }
}
ll ans;
void add(int f, int t) {
  edge[++num].nt = head[f];
  edge[num].to = t;
  head[f] = num;
}
int main() {
  scanf("%s", c + 1);
  len = strlen(c + 1);
  for (int i = 1; i <= len; ++i) {
    if (c[i] == '>')
      add(i + 1, i), vis[i] = 1;
    else
      add(i, i + 1), vis[i + 1] = 1;
  }
  for (int i = 1; i <= len + 1; ++i) {
    //	cout<<vis[i]<<"*";
    if (!vis[i])
      dfs(i, 0);
  } // puts("");
  for (int i = 1; i <= len + 1; ++i)
    ans += M[i]; //,cout<<M[i]<<" ";
                 //	puts("");
  cout << ans << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 5e5 + 10;
char c[maxn];
int len, head[maxn], num;
struct Le {
  int nt, to;
} edge[maxn << 1];
bool vis[maxn];
int M[maxn];
void dfs(int u, int dis) {
  M[u] = max(M[u], dis);
  for (int i = head[u]; i; i = edge[i].nt) {
    int v = edge[i].to;
    dfs(v, dis + 1);
  }
}
ll ans;
void add(int f, int t) {
  edge[++num].nt = head[f];
  edge[num].to = t;
  head[f] = num;
}
int main() {
  scanf("%s", c + 1);
  len = strlen(c + 1);
  for (int i = 1; i <= len; ++i) {
    if (c[i] == '>')
      add(i + 1, i), vis[i] = 1;
    else
      add(i, i + 1), vis[i + 1] = 1;
  }
  for (int i = 1; i <= len + 1; ++i) {
    //	cout<<vis[i]<<"*";
    if (!vis[i])
      dfs(i, 0);
  } // puts("");
  for (int i = 1; i <= len + 1; ++i)
    ans += M[i]; //,cout<<M[i]<<" ";
                 //	puts("");
  cout << ans << "\n";
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)

#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())

using namespace std;

const int maxn = 1e5 + 10;

int n;
int a[maxn], in[maxn];
vector<int> adj[maxn];

void dfs(int u) {
  for (int v : adj[u])
    if (a[v] <= a[u]) {
      a[v] = a[u] + 1;
      dfs(v);
    }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  n = sz(s);
  REP(i, n) if (s[i] == '<') {
    adj[i].push_back(i + 1);
    in[i + 1]++;
  }
  else {
    adj[i + 1].push_back(i);
    in[i]++;
  }
  REP(i, n + 1) if (!in[i]) { dfs(i); }
  long long res = 0;
  REP(i, n + 1) res += a[i];
  cout << res << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)

#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())

using namespace std;

const int maxn = 5e5 + 10;

int n;
int a[maxn], in[maxn];
vector<int> adj[maxn];

void dfs(int u) {
  for (int v : adj[u])
    if (a[v] <= a[u]) {
      a[v] = a[u] + 1;
      dfs(v);
    }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  n = sz(s);
  REP(i, n) if (s[i] == '<') {
    adj[i].push_back(i + 1);
    in[i + 1]++;
  }
  else {
    adj[i + 1].push_back(i);
    in[i]++;
  }
  REP(i, n + 1) if (!in[i]) { dfs(i); }
  long long res = 0;
  REP(i, n + 1) res += a[i];
  cout << res << "\n";

  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t, int64_t> pll;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define ALL(a) begin(a), end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

void solve() {
  vector<ll> dp(500010, 0);
  REP(i, 500005)
  dp[i + 1] = dp[i] + i + 1;
  string s;
  cin >> s;
  ll ans = 0;
  vector<ll> x;
  ll tem = 1;
  REP(i, s.size() - 1) {
    if (s[i] != s[i + 1]) {
      x.push_back(tem);
      ans += dp[tem];
      tem = 1;
    } else
      tem++;
  }
  x.push_back(tem);
  ans += dp[tem];
  // for(auto it:x)cout<<it<<endl;cout<<endl<<ans<<endl;

  if (s[0] == '>')
    x.erase(x.begin());
  if (s[s.size() - 1] == '<')
    x.erase(x.end() - 1);
  for (ll j = 0; j < x.size() - 1; j += 2) {
    ans -= min(x[j], x[j + 1]);
  }
  // for(auto it:x)cout<<it<<endl;
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t, int64_t> pll;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define ALL(a) begin(a), end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

void solve() {
  vector<ll> dp(500010, 0);
  REP(i, 500005)
  dp[i + 1] = dp[i] + i + 1;
  string s;
  cin >> s;
  ll ans = 0;
  vector<ll> x;
  ll tem = 1;
  REP(i, s.size() - 1) {
    if (s[i] != s[i + 1]) {
      x.push_back(tem);
      ans += dp[tem];
      tem = 1;
    } else
      tem++;
  }
  x.push_back(tem);
  ans += dp[tem];
  // for(auto it:x)cout<<it<<endl;cout<<endl<<ans<<endl;

  if (s[0] == '>')
    x.erase(x.begin());
  if (s[s.size() - 1] == '<')
    x.erase(x.end() - 1);
  if (x.size() >= 2)
    for (ll j = 0; j < x.size() - 1; j += 2) {
      ans -= min(x[j], x[j + 1]);
    }
  // for(auto it:x)cout<<it<<endl;
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <numeric>
using ll = long long;
using namespace std;
ll mod = 1e9;

int main() {
  string s;
  cin >> s;
  int N = s.size();
  vector<pair<int, ll>> ans;
  ll cnt(1);
  for (int i(0); i < N - 1; i++) {
    if (s[i] != s[i + 1]) {
      if (s[i] == '<') {
        ans.push_back({cnt, (ll)(cnt * (cnt - 1)) / 2});
      } else {
        int tmp = 0;
        if (!ans.empty()) {
          if (ans.back().first > cnt)
            tmp = ans.back().first - cnt;
          ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
        } else {
          ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
        }
      }
      cnt = 1;
    } else {
      cnt++;
    }
  }

  if (s[N - 1] == '<') {
    ans.push_back({cnt, (ll)(cnt * (cnt + 1)) / 2});
  } else {
    int tmp = 0;
    if (ans.back().first > cnt)
      tmp = ans.back().first - cnt;
    ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
  }

  ll sum(0);
  for (int i(0); i < ans.size(); i++) {
    sum += ans[i].second;
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <numeric>
using ll = long long;
using namespace std;
ll mod = 1e9;

int main() {
  string s;
  cin >> s;
  int N = s.size();
  vector<pair<int, ll>> ans;
  ll cnt(1);
  for (int i(0); i < N - 1; i++) {
    if (s[i] != s[i + 1]) {
      if (s[i] == '<') {
        ans.push_back({cnt, (ll)(cnt * (cnt - 1)) / 2});
      } else {
        int tmp = 0;
        if (!ans.empty()) {
          if (ans.back().first > cnt)
            tmp = ans.back().first - cnt;
          ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
        } else {
          ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
        }
      }
      cnt = 1;
    } else {
      cnt++;
    }
  }

  if (s[N - 1] == '<') {
    ans.push_back({cnt, (ll)(cnt * (cnt + 1)) / 2});
  } else {
    int tmp = 0;
    if (!ans.empty()) {
      if (ans.back().first > cnt)
        tmp = ans.back().first - cnt;
      ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
    } else {
      ans.push_back({cnt, tmp + (ll)(cnt * (cnt + 1)) / 2});
    }
  }

  ll sum(0);
  for (int i(0); i < ans.size(); i++) {
    sum += ans[i].second;
  }
  cout << sum << endl;
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
char s[200000];
int c[2000000], b[2000000];
signed main() {
  io;
  cin >> s + 1;
  int n = strlen(s + 1) + 1;
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] == '<')
      b[i] = b[i - 1] + 1;
  }
  for (int i = n - 1; i; i--) {
    if (s[i] == '>')
      c[i] = c[i + 1] + 1;
  }
  int ans = 0;
  rep(i, 1, n) ans += max(c[i], b[i]);
  cout << ans << endl;

  getchar(); //
  getchar();
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
char s[2000000];
int c[2000000], b[2000000];
signed main() {
  io;
  cin >> s + 1;
  int n = strlen(s + 1) + 1;
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] == '<')
      b[i] = b[i - 1] + 1;
  }
  for (int i = n - 1; i; i--) {
    if (s[i] == '>')
      c[i] = c[i + 1] + 1;
  }
  int ans = 0;
  rep(i, 1, n) ans += max(c[i], b[i]);
  cout << ans << endl;

  getchar(); //
  getchar();
}
Problem p02873 (C++)

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int, int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9 + 7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

ll sum(ll n, ll m) {
  ll a = max(n, m);
  ll b = min(n, m);

  return (a * (a + 1) / 2 + b * (b - 1) / 2);
}

int main() {
  string s;
  cin >> s;

  ll n = s.size();

  vector<ll> a;

  ll count = 1;

  rep(i, n - 1) {
    if (s[i] == s[i + 1]) {
      count++;
    } else {
      a.PB(count);
      count = 1;
    }
    if (i == n - 2) {
      a.PB(count);
    }
  }

  ll ans = 0;
  ll num = a.size();

  if (s[0] == '>') {
    ans += sum(0, a[0]);
    a.erase(a.begin());
    num--;
  }

  rep(i, num / 2) ans += sum(a[2 * i], a[2 * i + 1]);
  if (num % 2 == 1) {
    ans += sum(a[num - 1], 0);
  }

  cout << ans << endl;
}

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int, int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9 + 7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

ll sum(ll n, ll m) {
  ll a = max(n, m);
  ll b = min(n, m);

  return (a * (a + 1) / 2 + b * (b - 1) / 2);
}

int main() {
  string s;
  cin >> s;

  ll n = s.size();

  vector<ll> a;

  ll count = 1;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }

  rep(i, n - 1) {
    if (s[i] == s[i + 1]) {
      count++;
    } else {
      a.PB(count);
      count = 1;
    }
    if (i == n - 2) {
      a.PB(count);
    }
  }

  ll ans = 0;
  ll num = a.size();

  if (s[0] == '>') {
    ans += sum(0, a[0]);
    a.erase(a.begin());
    num--;
  }

  rep(i, num / 2) ans += sum(a[2 * i], a[2 * i + 1]);
  if (num % 2 == 1) {
    ans += sum(a[num - 1], 0);
  }

  cout << ans << endl;
}
Problem p02873 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

bool good(int index, vector<int> ans, string s) {
  int n = ans.size();
  if (ans[index] != -1)
    return false;
  if (index != 0) {
    if (s[index - 1] == '<' && ans[index - 1] == -1)
      return false;
  }
  if (index != n - 1) {
    if (s[index] == '>' && ans[index + 1] == -1)
      return false;
  }
  return true;
}

int main() {
#ifdef LOCAL
  freopen("A_input.txt", "r", stdin);
  // freopen("A_output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size() + 1;
  vector<int> ans(n, -1);
  queue<int> possible;
  for (int i = 0; i < n; ++i) {
    if (good(i, ans, s)) {
      possible.push(i);
      ans[i] = -2;
    }
  }
  while (possible.size()) {
    int V = possible.front();
    possible.pop();
    int val = 0;
    if (V != 0)
      val = max(val, ans[V - 1] + 1);
    if (V != n - 1)
      val = max(val, ans[V + 1] + 1);
    ans[V] = val;
    // cout << V << " " << val << endl;
    for (int j = V - 1; j <= V + 1; j++) {
      if (j >= 0 && j <= n - 1 && good(j, ans, s)) {
        possible.push(j);
        ans[j] = -2;
      }
    }
  }
  ll an = 0;
  for (int i = 0; i < n; ++i)
    an += ans[i];
  cout << an;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

bool good(int index, vector<int> &ans, string &s) {
  int n = ans.size();
  if (ans[index] != -1)
    return false;
  if (index != 0) {
    if (s[index - 1] == '<' && ans[index - 1] == -1)
      return false;
  }
  if (index != n - 1) {
    if (s[index] == '>' && ans[index + 1] == -1)
      return false;
  }
  return true;
}

int main() {
#ifdef LOCAL
  freopen("A_input.txt", "r", stdin);
  // freopen("A_output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size() + 1;
  vector<int> ans(n, -1);
  queue<int> possible;
  for (int i = 0; i < n; ++i) {
    if (good(i, ans, s)) {
      possible.push(i);
      ans[i] = -2;
    }
  }
  while (possible.size()) {
    int V = possible.front();
    possible.pop();
    int val = 0;
    if (V != 0)
      val = max(val, ans[V - 1] + 1);
    if (V != n - 1)
      val = max(val, ans[V + 1] + 1);
    ans[V] = val;
    // cout << V << " " << val << endl;
    for (int j = V - 1; j <= V + 1; j++) {
      if (j >= 0 && j <= n - 1 && good(j, ans, s)) {
        possible.push(j);
        ans[j] = -2;
      }
    }
  }
  ll an = 0;
  for (int i = 0; i < n; ++i)
    an += ans[i];
  cout << an;
}
Problem p02873 (C++)

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

typedef long long ll;
const int maxn = 100005;

inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9')
    sum = sum * 10 + c - 48, c = getchar();
  return sum;
}

char s[maxn];
int n, a[maxn], b[maxn];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  ll sum = 0;
  for (int i = 1; i <= n; ++i)
    a[i] = s[i] == '<' ? a[i - 1] + 1 : 0;
  for (int i = n - 1; ~i; --i)
    b[i] = s[i + 1] == '>' ? b[i + 1] + 1 : 0;
  for (int i = 0; i <= n; ++i)
    sum += max(a[i], b[i]);
  printf("%lld\n", sum);

  return 0;
}


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

typedef long long ll;
const int maxn = 500005;

inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9')
    sum = sum * 10 + c - 48, c = getchar();
  return sum;
}

char s[maxn];
int n, a[maxn], b[maxn];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  ll sum = 0;
  for (int i = 1; i <= n; ++i)
    a[i] = s[i] == '<' ? a[i - 1] + 1 : 0;
  for (int i = n - 1; ~i; --i)
    b[i] = s[i + 1] == '>' ? b[i + 1] + 1 : 0;
  for (int i = 0; i <= n; ++i)
    sum += max(a[i], b[i]);
  printf("%lld\n", sum);

  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  list<int> l(1), r(1);
  int cnt = 0;
  for (auto &&i : str) {
    if (i == '<') {
      cnt++;
    } else {
      if (l.size())
        cnt = 0;
    }
    l.push_back(cnt);
  }
  reverse(begin(str), end(str));
  cnt = 0;
  for (auto &&i : str) {
    if (i == '>') {
      cnt++;
    } else {
      cnt = 0;
    }
    r.push_front(cnt);
  }
  long long sum = 0;
  while (!l.empty()) {
    sum += max(l.front(), r.front());
    l.pop_front();
    r.pop_front();
  }
  cout << sum << "\n";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  list<int> l(1), r(1);
  int cnt = 0;
  for (auto &&i : str) {
    if (i == '<') {
      cnt++;
    } else {
      cnt = 0;
    }
    l.push_back(cnt);
  }
  reverse(begin(str), end(str));
  cnt = 0;
  for (auto &&i : str) {
    if (i == '>') {
      cnt++;
    } else {
      cnt = 0;
    }
    r.push_front(cnt);
  }
  long long sum = 0;
  while (!l.empty()) {
    sum += max(l.front(), r.front());
    l.pop_front();
    r.pop_front();
  }
  cout << sum << "\n";
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 200010;

int n;
vector<int> adj[maxn];
int dp[maxn];

int dfs(int u) {
  if (dp[u] != -1) {
    return dp[u];
  }
  dp[u] = 0;
  for (int v : adj[u]) {
    dp[u] = max(dp[u], dfs(v) + 1);
  }
  return dp[u];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  n = s.length() + 1;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == '<') {
      adj[i + 1].push_back(i);
    } else {
      adj[i].push_back(i + 1);
    }
  }
  for (int i = 0; i < n; ++i) {
    dp[i] = -1;
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += dfs(i);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 500010;

int n;
vector<int> adj[maxn];
int dp[maxn];

int dfs(int u) {
  if (dp[u] != -1) {
    return dp[u];
  }
  dp[u] = 0;
  for (int v : adj[u]) {
    dp[u] = max(dp[u], dfs(v) + 1);
  }
  return dp[u];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  n = s.length() + 1;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == '<') {
      adj[i + 1].push_back(i);
    } else {
      adj[i].push_back(i + 1);
    }
  }
  for (int i = 0; i < n; ++i) {
    dp[i] = -1;
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += dfs(i);
  }
  cout << ans << endl;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100005;
char s[max_n];
int l[max_n], r[max_n];
int main() {
  scanf(" %s", s + 1);
  int n = strlen(s + 1) + 1;
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] == '<')
      l[i] = l[i - 1] + 1;
  }
  for (int i = n - 1; i >= 1; i--) {
    if (s[i] == '>')
      r[i] = r[i + 1] + 1;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += max(l[i], r[i]);
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 500005;
char s[max_n];
int l[max_n], r[max_n];
int main() {
  scanf(" %s", s + 1);
  int n = strlen(s + 1) + 1;
  for (int i = 2; i <= n; i++) {
    if (s[i - 1] == '<')
      l[i] = l[i - 1] + 1;
  }
  for (int i = n - 1; i >= 1; i--) {
    if (s[i] == '>')
      r[i] = r[i + 1] + 1;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++)
    ans += max(l[i], r[i]);
  printf("%lld\n", ans);
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  vector<ll> a;
  string s;
  cin >> s;
  int n = s.length();
  char init = s[0], last = s[n - 1];
  ll count = 1;
  FOR(i, 1, n) {
    if (s[i] == s[i - 1]) {
      count++;
    } else {
      a.push_back(count);
      count = 1;
    }
  }
  a.push_back(count);

  ll ans = 0;
  if (init == '>') {
    ans += a[0] * (a[0] + 1) / 2;
    a.erase(a.begin());
  }
  REP(i, a.size() - 1) {
    if (i % 2 != 0)
      continue;
    ll mi = min(a[i], a[i + 1]);
    ll ma = max(a[i], a[i + 1]);
    ans += mi * (mi - 1) / 2;
    ans += ma * (ma + 1) / 2;
  }
  if (last == '<') {
    ans += a[a.size() - 1] * (a[a.size() - 1] + 1) / 2;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  vector<ll> a;
  string s;
  cin >> s;
  int n = s.length();
  char init = s[0], last = s[n - 1];
  ll count = 1;
  FOR(i, 1, n) {
    if (s[i] == s[i - 1]) {
      count++;
    } else {
      a.push_back(count);
      count = 1;
    }
  }
  a.push_back(count);

  ll ans = 0;
  if (init == '>') {
    ans += a[0] * (a[0] + 1) / 2;
    a.erase(a.begin());
    if (a.empty()) {
      cout << ans << endl;
      return 0;
    }
  }
  REP(i, a.size() - 1) {
    if (i % 2 != 0)
      continue;
    ll mi = min(a[i], a[i + 1]);
    ll ma = max(a[i], a[i + 1]);
    ans += mi * (mi - 1) / 2;
    ans += ma * (ma + 1) / 2;
  }
  if (last == '<') {
    ans += a[a.size() - 1] * (a[a.size() - 1] + 1) / 2;
  }
  cout << ans << endl;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <deque>
#include <stdio.h>
#include <utility>

using namespace std;
using ll = long long;

ll max(ll x, ll y) {
  if (x < y) {
    return y;
  } else {
    return x;
  }
}

int main(void) {
  ll ans = 0LL;
  deque<pair<char, ll>> v = {make_pair(getchar(), 1LL)};
  int d;
  while ((d = getchar()) != EOF) {
    if (d != v.back().first) {
      v.push_back(make_pair(d, 0LL));
    }
    v.back().second++;
  }
  if (v.front().first == '>') {
    ans += (v.front().second + 1LL) * v.front().second / 2LL;
    v.pop_front();
  }
  if (v.back().first == '<') {
    ans += (v.back().second + 1LL) * v.back().second / 2LL;
    v.pop_back();
  }
  while (!v.empty()) {
    ll open, close;
    open = v.front().second;
    v.pop_front();
    close = v.front().second;
    v.pop_front();
    ans += (open - 1LL) * open / 2LL + (close - 1LL) * close / 2LL +
           max(open, close);
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <deque>
#include <stdio.h>
#include <utility>

using namespace std;
using ll = long long;

ll max(ll x, ll y) {
  if (x < y) {
    return y;
  } else {
    return x;
  }
}

int main(void) {
  ll ans = 0LL;
  deque<pair<char, ll>> v = {make_pair(getchar(), 1LL)};
  int d;
  while ((d = getchar()) != EOF) {
    if (d == '\n') {
      continue;
    }
    if (d != v.back().first) {
      v.push_back(make_pair(d, 0LL));
    }
    v.back().second++;
  }
  if (v.front().first == '>') {
    ans += (v.front().second + 1LL) * v.front().second / 2LL;
    v.pop_front();
  }
  if (v.back().first == '<') {
    ans += (v.back().second + 1LL) * v.back().second / 2LL;
    v.pop_back();
  }
  while (!v.empty()) {
    ll open, close;
    open = v.front().second;
    v.pop_front();
    close = v.front().second;
    v.pop_front();
    ans += (open - 1LL) * open / 2LL + (close - 1LL) * close / 2LL +
           max(open, close);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>
#define pf push_front

const int maxn = 1000 * 100 + 5;
int a[maxn];
vector<int> v;

int32_t main() {
  string s;
  cin >> s;
  for (int i = 0; i < SZ(s); i++) {
    if (i == SZ(s) - 1 and s[i] == '>')
      v.pb(SZ(s));
    else if ((i == 0 and s[i] == '<') or
             (i > 0 and s[i] == '<' and s[i - 1] == '>'))
      v.pb(i);
  }
  for (int i = 0; i < SZ(v); i++) {
    int x = v[i];
    for (int j = x + 1; j < SZ(s) + 1 and s[j - 1] == '<'; j++) {
      xmax(a[j], a[j - 1] + 1);
    }
    for (int j = x - 1; j >= 0 and s[j] == '>'; j--) {
      xmax(a[j], a[j + 1] + 1);
    }
  }
  int sum = 0;
  for (int i = 0; i < SZ(s) + 1; i++)
    sum += a[i];
  cout << sum << endl;
  return false;
}


Fixed submission:
/// not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int>>
#define pf push_front

const int maxn = 5000 * 100 + 5;
int a[maxn];
vector<int> v;

int32_t main() {
  string s;
  cin >> s;
  for (int i = 0; i < SZ(s); i++) {
    if (i == SZ(s) - 1 and s[i] == '>')
      v.pb(SZ(s));
    else if ((i == 0 and s[i] == '<') or
             (i > 0 and s[i] == '<' and s[i - 1] == '>'))
      v.pb(i);
  }
  for (int i = 0; i < SZ(v); i++) {
    int x = v[i];
    for (int j = x + 1; j < SZ(s) + 1 and s[j - 1] == '<'; j++) {
      xmax(a[j], a[j - 1] + 1);
    }
    for (int j = x - 1; j >= 0 and s[j] == '>'; j--) {
      xmax(a[j], a[j + 1] + 1);
    }
  }
  int sum = 0;
  for (int i = 0; i < SZ(s) + 1; i++)
    sum += a[i];
  cout << sum << endl;
  return false;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x, TYPE y) {
  x < y ? x = y : 0;
}
template <typename TYPE> inline void chkmin(TYPE &x, TYPE y) {
  y < x ? x = y : 0;
}
template <typename TYPE> void readint(TYPE &x) {
  x = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  x *= f;
}
const int MAXN = 505;

int n, a[MAXN];
char s[MAXN];

int main() {
#ifndef ONLINE_JUDGE
  // freopen("code.in","r",stdin);
  // freopen("code.out","w",stdout);
#endif
  ll ans = 0;
  scanf("%s", s + 1);
  n = strlen(s + 1) + 1;
  s[0] = '>';
  s[n] = '<';
  for (int i = 1; i <= n; ++i)
    if (s[i - 1] == '>' && s[i] == '<') {
      a[i] = 0;
      for (int j = i - 1; s[j] == '>' && j; --j)
        chkmax(a[j], a[j + 1] + 1);
      for (int j = i + 1; s[j - 1] == '<' && j <= n; ++j)
        chkmax(a[j], a[j - 1] + 1);
    }
  for (int i = 1; i <= n; ++i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x, TYPE y) {
  x < y ? x = y : 0;
}
template <typename TYPE> inline void chkmin(TYPE &x, TYPE y) {
  y < x ? x = y : 0;
}
template <typename TYPE> void readint(TYPE &x) {
  x = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  x *= f;
}
const int MAXN = 500005;

int n, a[MAXN];
char s[MAXN];

int main() {
#ifndef ONLINE_JUDGE
  // freopen("code.in","r",stdin);
  // freopen("code.out","w",stdout);
#endif
  ll ans = 0;
  scanf("%s", s + 1);
  n = strlen(s + 1) + 1;
  s[0] = '>';
  s[n] = '<';
  for (int i = 1; i <= n; ++i)
    if (s[i - 1] == '>' && s[i] == '<') {
      a[i] = 0;
      for (int j = i - 1; s[j] == '>' && j; --j)
        chkmax(a[j], a[j + 1] + 1);
      for (int j = i + 1; s[j - 1] == '<' && j <= n; ++j)
        chkmax(a[j], a[j - 1] + 1);
    }
  for (int i = 1; i <= n; ++i)
    ans += a[i];
  printf("%lld\n", ans);
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

ll a[100100];
queue<int> q;

int main(void) {
  int n, i;
  ll b = 0ll, ans = 0ll;
  string s;
  cin >> s;
  n = s.l_ength();
  if (s[0] == '<') {
    q.push(0);
  }
  if (s[n - 1] == '>') {
    q.push(n);
  }
  for (i = 1; i < n; ++i) {
    if (s[i - 1] == '>' && s[i] == '<') {
      q.push(i);
    }
  }
  while (!q.empty()) {
    i = q.front();
    q.pop();
    if (i == 0) {
      if (s[0] == '<') {
        a[1] = max(a[1], a[0] + 1);
        q.push(1);
      }
    } else if (i == n) {
      if (s[n - 1] == '>') {
        a[n - 1] = max(a[n - 1], a[n] + 1);
        q.push(n - 1);
      }
    } else {
      if (s[i - 1] == '>') {
        a[i - 1] = max(a[i - 1], a[i] + 1);
        q.push(i - 1);
      }
      if (s[i] == '<') {
        a[i + 1] = max(a[i + 1], a[i] + 1);
        q.push(i + 1);
      }
    }
  }
  for (i = 0; i <= n; ++i) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

ll a[555555];
queue<int> q;

int main(void) {
  int n, i;
  ll b = 0ll, ans = 0ll;
  string s;
  cin >> s;
  n = s.l_ength();
  if (s[0] == '<') {
    q.push(0);
  }
  if (s[n - 1] == '>') {
    q.push(n);
  }
  for (i = 1; i < n; ++i) {
    if (s[i - 1] == '>' && s[i] == '<') {
      q.push(i);
    }
  }
  while (!q.empty()) {
    i = q.front();
    q.pop();
    if (i == 0) {
      if (s[0] == '<') {
        a[1] = max(a[1], a[0] + 1);
        q.push(1);
      }
    } else if (i == n) {
      if (s[n - 1] == '>') {
        a[n - 1] = max(a[n - 1], a[n] + 1);
        q.push(n - 1);
      }
    } else {
      if (s[i - 1] == '>') {
        a[i - 1] = max(a[i - 1], a[i] + 1);
        q.push(i - 1);
      }
      if (s[i] == '<') {
        a[i + 1] = max(a[i + 1], a[i] + 1);
        q.push(i + 1);
      }
    }
  }
  for (i = 0; i <= n; ++i) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;
  vector<int64_t> A(S.size() + 1, 0);
  for (int i = 1; i <= S.size(); i++) {
    if (S.at(i - 1) == '<') {
      A.at(i) = A.at(i - 1) + 1;
    } else {
      int64_t cnt = 0;
      for (int j = i - 1; j < S.size(); j++) {
        if (S.at(j) == '<')
          break;
        cnt++;
      }
      A.at(i - 1) = max(A.at(i - 1), cnt);
      int64_t tmp = cnt - 1, j = i;
      while (tmp >= 0) {
        A.at(j) = tmp;
        tmp--;
        j++;
      }
    }
  }
  int64_t ans = 0;
  for (auto a : A)
    ans += a;
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  vector<int64_t> A(S.size() + 1, 0);
  for (int i = 1; i <= S.size(); i++) {
    if (S.at(i - 1) == '<') {
      A.at(i) = A.at(i - 1) + 1;
    } else {
      int64_t cnt = 0;
      for (int j = i - 1; j < S.size(); j++) {
        if (S.at(j) == '<')
          break;
        cnt++;
      }
      A.at(i - 1) = max(A.at(i - 1), cnt);
      int64_t tmp = cnt - 1, j = i;
      while (tmp >= 0) {
        A.at(j) = tmp;
        tmp--;
        j++;
      }
      i = j - 1;
    }
  }
  int64_t ans = 0;
  for (auto a : A)
    ans += a;
  cout << ans << endl;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define f(i, n) for (int i = 0; i < (int)(n); i++)
#define N 200010

int main() {
  char a[N];
  long long b[N];
  f(i, N) a[i] = 0;
  int n, k;
  int x, y, z;
  long long s, ans;
  bool v = true;
  ans = 0;
  scanf("%s", a);
  n = strlen(a);
  b[0] = 0;
  f(i, n) {
    if (a[i] == '<')
      b[i + 1] = b[i] + 1;
    else
      b[i + 1] = 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == '>')
      b[i] = max(b[i], b[i + 1] + 1);
  }
  f(i, n + 1) ans += b[i];
  printf("%lld\n", ans);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define f(i, n) for (int i = 0; i < (int)(n); i++)
#define N 500010

int main() {
  char a[N];
  long long b[N];
  f(i, N) a[i] = 0;
  int n, k;
  int x, y, z;
  long long s, ans;
  bool v = true;
  ans = 0;
  scanf("%s", a);
  n = strlen(a);
  b[0] = 0;
  f(i, n) {
    if (a[i] == '<')
      b[i + 1] = b[i] + 1;
    else
      b[i + 1] = 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == '>')
      b[i] = max(b[i], b[i + 1] + 1);
  }
  f(i, n + 1) ans += b[i];
  printf("%lld\n", ans);

  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int i;
  int chk = 0;
  long ans = 0;
  int a[n + 1];
  for (i = 0; i < n + 1; i++) {
    a[i] = 0;
  }

  while (chk == 0) {
    chk = 1;
    for (i = 0; i < n; i++) {
      if (s[i] == '<') {
        if (a[i] >= a[i + 1]) {
          a[i + 1] = a[i] + 1;
          chk = 0;
        }
      } else {
        if (a[i] <= a[i + 1]) {
          a[i] = a[i + 1] + 1;
          chk = 0;
        }
      }
    }
  }
  for (i = 0; i <= n; i++) {
    ans += a[i];
  }
  cout << ans;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int i;
  int chk = 0;
  long ans = 0;
  int a[n + 1];
  for (i = 0; i < n + 1; i++) {
    a[i] = 0;
  }

  while (chk == 0) {
    chk = 1;
    for (i = 0; i < n; i++) {
      if (s[i] == '<') {
        if (a[i] >= a[i + 1]) {
          a[i + 1] = a[i] + 1;
          chk = 0;
        }
      } else {
        if (a[i] <= a[i + 1]) {
          a[i] = a[i + 1] + 1;
          chk = 0;
        }
      }
    }
    for (i = n - 1; i >= 0; i--) {
      if (s[i] == '<') {
        if (a[i] >= a[i + 1]) {
          a[i + 1] = a[i] + 1;
          chk = 0;
        }
      } else {
        if (a[i] <= a[i + 1]) {
          a[i] = a[i + 1] + 1;
          chk = 0;
        }
      }
    }
  }
  for (i = 0; i <= n; i++) {
    ans += a[i];
  }
  cout << ans;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300100;
char str[maxn];
int l[maxn], r[maxn];
int Max(int x, int y) { return x > y ? x : y; }
int main() {
  //	freopen("A.in","r",stdin);
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  for (int i = 1; i <= n; i++) {
    if (str[i] == '<')
      l[i] = l[i - 1] + 1;
    else
      l[i] = 0;
  }
  for (int i = n; i >= 1; i--) {
    if (str[i] == '>')
      r[i - 1] = r[i] + 1;
    else
      r[i - 1] = 0;
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++)
    ans += Max(l[i], r[i]);
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500100;
char str[maxn];
int l[maxn], r[maxn];
int Max(int x, int y) { return x > y ? x : y; }
int main() {
  //	freopen("A.in","r",stdin);
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  for (int i = 1; i <= n; i++) {
    if (str[i] == '<')
      l[i] = l[i - 1] + 1;
    else
      l[i] = 0;
  }
  for (int i = n; i >= 1; i--) {
    if (str[i] == '>')
      r[i - 1] = r[i] + 1;
    else
      r[i - 1] = 0;
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++)
    ans += Max(l[i], r[i]);
  printf("%lld\n", ans);
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
char s[maxn];
ll ans = 0;
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      cur++;
      ans += cur;
    } else {
      int j = i;
      while (j + 1 < n && s[j + 1] == s[j])
        j++;
      //			cout<<i<<"->"<<j<<endl;
      ll siz = j - i + 1;
      if (siz >= cur) {
        ans -= cur;
        ans += siz * (siz + 1) / 2;
      } else {
        ans += (siz - 1) * (siz) / 2;
      }
      cur = 0;
      i = j;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 233;
char s[maxn];
ll ans = 0;
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      cur++;
      ans += cur;
    } else {
      int j = i;
      while (j + 1 < n && s[j + 1] == s[j])
        j++;
      //			cout<<i<<"->"<<j<<endl;
      ll siz = j - i + 1;
      if (siz >= cur) {
        ans -= cur;
        ans += siz * (siz + 1) / 2;
      } else {
        ans += (siz - 1) * (siz) / 2;
      }
      cur = 0;
      i = j;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 100000;
char s[maxn + 5];
int n;
int a[maxn + 5], v[maxn + 5];
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  s[0] = '>';
  s[n + 1] = '<';
  for (int i = 1; i <= n + 1; i++) {
    if (s[i - 1] == '>' && s[i] == '<')
      v[i] = -1;
    if (s[i - 1] == '<' && s[i] == '>')
      v[i] = 1;
  }
  int flag = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (v[i] == -1)
      flag = 1;
    else if (!flag)
      continue;
    else {
      if (v[i] == 1)
        flag = 0;
      a[i] = max(a[i], a[i - 1] + 1);
    }
  }
  flag = 0;
  for (int i = n + 1; i >= 1; i--) {
    if (v[i] == -1)
      flag = 1;
    else if (!flag)
      continue;
    else {
      if (v[i] == 1)
        flag = 0;
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  int sum = 0;
  for (int i = 1; i <= n + 1; i++)
    sum += a[i];
  printf("%lld\n", sum);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 500000;
char s[maxn + 5];
int n;
int a[maxn + 5], v[maxn + 5];
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  s[0] = '>';
  s[n + 1] = '<';
  for (int i = 1; i <= n + 1; i++) {
    if (s[i - 1] == '>' && s[i] == '<')
      v[i] = -1;
    if (s[i - 1] == '<' && s[i] == '>')
      v[i] = 1;
  }
  int flag = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (v[i] == -1)
      flag = 1;
    else if (!flag)
      continue;
    else {
      if (v[i] == 1)
        flag = 0;
      a[i] = max(a[i], a[i - 1] + 1);
    }
  }
  flag = 0;
  for (int i = n + 1; i >= 1; i--) {
    if (v[i] == -1)
      flag = 1;
    else if (!flag)
      continue;
    else {
      if (v[i] == 1)
        flag = 0;
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  int sum = 0;
  for (int i = 1; i <= n + 1; i++)
    sum += a[i];
  printf("%lld\n", sum);
  return 0;
}
Problem p02873 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 100100;

int N;
string s;
int A[MAXN];
int blo[MAXN];
int res[MAXN];

int main() {
  ios_base::sync_with_stdio(0);

  cin >> s;
  N = s.length();

  blo[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == '<') {
      blo[i] = 0;
    } else {
      blo[i] = blo[i + 1] + 1;
    }
  }

  res[0] = blo[0];
  for (int i = 0; i < N; i++) {
    if (s[i] == '<') {
      res[i + 1] = max(blo[i + 1], res[i] + 1);
    } else {
      res[i + 1] = blo[i + 1];
    }
  }

  ll ans = 0;
  for (int i = 0; i <= N; i++)
    ans += res[i];
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 500100;

int N;
string s;
int A[MAXN];
int blo[MAXN];
int res[MAXN];

int main() {
  ios_base::sync_with_stdio(0);

  cin >> s;
  N = s.length();

  blo[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == '<') {
      blo[i] = 0;
    } else {
      blo[i] = blo[i + 1] + 1;
    }
  }

  res[0] = blo[0];
  for (int i = 0; i < N; i++) {
    if (s[i] == '<') {
      res[i + 1] = max(blo[i + 1], res[i] + 1);
    } else {
      res[i + 1] = blo[i + 1];
    }
  }

  ll ans = 0;
  for (int i = 0; i <= N; i++)
    ans += res[i];
  cout << ans << "\n";
}