Problem:
Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

2 \leq N \leq 5 \times 10^5

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>
typedef unsigned long long ull;
typedef long long ll;
#define MOD 10000000000　+　7    //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
char cha[500000];
/*整数をqsortする為だけのもの*/
long long compare(const long long *a, const long long *b)
{
    if (*a < *b)
        return -1;
    else if (*a > *b)
        return 1;
    return 0;
}
/*intで収まる範囲であってくれ*/
ll nCr(int n, int r)
{
    ll val = 1;
    int i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(int n, int r)
{
    ll val = 1;
    int i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}
/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/
ll sm(ll num)
{ //<の個数入れる
    if (num == 1)
    {
        return 1;
    }
    if (num < 1)
    {
        return 0;
    }
    return num * (num + 1) / 2;
}
int main()
{
    ll N, K, i, j, length, tempr = 0, templ = 0;
    ll sum = 0;
    ll right = 0, left = 0, change = 0, temp = 0;
    memset(cha, 0, sizeof(cha));
    scanf("%s", &cha);
    length = strlen(cha);
    /*if (*(cha + 0) == '>')
        {
            right++;
        }
        else if (*(cha + 0) == '<')
        {
            left++;
        }*/
    for (i = 0; i < length; i++)
    {

        if (*(cha + i) == '>')
        {
            right++;
        }
        else if (*(cha + i) == '<')
        {
            left++;
        }

        if (*(cha + i) != *(cha + i + 1))
        {
            if(change==0){
                if(right>0){
                    temp=right;
                }
                if(left>0){
                    temp =left;
                }
                if(*(cha +i) == '>'){
                temp =0;
            }
            }
            
            change++;
        }
        if (change == 2)
        {
            sum += sm(right);
            sum += sm(left);
            sum -= temp;
            if (*(cha + i) == '<')
            {
                if(right>=left){
                    sum -=left;
                }
                else{
                    sum -= right;
                }
                temp = sm(left);
                right =0;
            }
            else
            {   
                temp = sm(right);
                left = 0;
            }
            change = 1;
        }
    }
    /* if (*(cha + length -1) == '>')
        {
            right++;
        }
        else if (*(cha + length -1) == '<')
        {
            left++;
        }
            if (right > left)
            {
                sum += sm(right);
                sum += sm(left - 1);
            }
            else
            {
                sum += sm(left);
                sum += sm(right - 1);
            }
        */
    if(sum==0){
         sum += sm(right);
            sum += sm(left);
    }
    printf("%lld", sum);
    return 0;
}