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# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ForATCODER
{
    public class Program
    {
        ///template
        ///
        /// String[] s = Console.ReadLine().Split(' ');
        ///   long[] nk =  s2larray(Console.ReadLine().Split(' '));
        ///   

        public static void Main(string[] args)
        {
            String dat = Console.ReadLine();
            int[] dat_ = new int[dat.Length];
            long[] res = new long[dat.Length+1];
            //load
            for(int i = 0; i <  dat.Length;i++)
            {
                dat_[i] = dat[i] == '>' ? 1 : 0;
            }
            int mark1 = -1;
            if (dat_[0] == 1)
            {
                res[0] = 1;
                mark1 = 0;
            }
            else { res[0] = 0; mark1 = 1; }
            //loop
            int mark0 = -1;
            for (int i = 1; i < res.Length; i++)
            {
                if(dat_[i-1]==1) //>
                {
                    //if (dat_[i] == 0) res[i] = 0; else res[i] = res[i-1]+1;
                    if(i>0 && res[i-1]==0)res[i]--;
                    if(i>1 && dat_[i - 2]!= dat_[i - 1])
                    {
                        mark0 = i;
                    }
                    if (res[i] < 0)
                    {
                        addarray(res, mark1, i);
                      /*  if (mark1 > 0)
                        {
                            addarray(res, mark1, i);
                        }
                        else
                        {
                            if (res[0] == 0) addarray(res, 1, i); else addarray(res, 0, i);
                        }*/
                    }
                }
                else
                {
                    res[i] = res[i - 1] +1;
                }
                if(res[i]==0 && dat_[i] == 0) //<
                {
                    mark1 = i + 1;
                }
                if (i>2 &&  res[i] == 0 &&  dat_[i-1] == 1 && dat_[i-2] == 0) //>
                {
                    mark1 = i;
                }
                else if (res[i] == 0 && dat_[i-1] == 1)
                {
                  //  mark1 = i;
                }
            }
            Console.WriteLine(res.Sum());
            

        }
        static void addarray(long[] arr ,int start,int end)
        {
            for(int i = start; i <= end;i++)
            {
                arr[i]++;
            }
        }
        public static decimal Sqrt(decimal x)
        {
            decimal sqrt_x = (decimal)Math.Sqrt((long)x);
            for (int i = 0; i < 10; ++i)
                sqrt_x = 0.5m * (sqrt_x + x / sqrt_x);
            return sqrt_x;
        }
        static   long summ(long s)
        {
            if (s == 1) return 1;
            return s + summ(s-1);
        }
        public static bool checka(int[] a, int m)
        {
            int back = 1;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] >= 1 && a[i] <= m)
                {
                    if (a[i] >= back)
                    {
                        back = a[i];
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        public static ulong pow(int a, int b)
        {
            ulong res = 1;
            for (int i = 0; i < b; i++)
            {
                res *= (ulong)a;
            }
            return res;
        }
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static long s2l(String s)
        {
            return Convert.ToInt64(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] s2iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] s2larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
        static ulong[] s2larray2(String[] src)
        {
            int len = src.Length;
            ulong[] res = new ulong[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToUInt64(src[i]);
            }
            return res;
        }

        static long C(int n, int r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            long ans = 1;
            int i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }
        static long C(long n, long r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            long ans = 1;
            int i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }
        static ulong C(ulong n, ulong r)
        {
            if (n <= 1) return 0;
            if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
            ulong ans = 1;
            ulong i;

            for (i = 1; i <= r; i++)
            {
                ans *= n - r + i;
                ans /= i;
            }

            return ans;
        }
    }

}