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-csc 3.5.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var S = ReadLine();

            var zip = Zip(S);

            long ans = 0;
            for (int i = 0; i < zip.Length; i += 2)
            {
                var hutogo = zip.Substring(i, 1);
                var cnt = int.Parse(zip.Substring(i + 1, 1));

                ans += cnt * (cnt + 1) / 2;

                if (i != 0)
                {
                    var preHutogo = zip.Substring(i - 2, 1);
                    var preCnt = int.Parse(zip.Substring(i - 1, 1));

                    if (hutogo == ">")
                    {
                        ans -= Min(preCnt, cnt);
                    }
                }
            }
            WriteLine(ans);
        }

        public static string Zip(string s)
        {
            var sb = new StringBuilder();

            for (int i = 0; i < s.Length;)
            {
                string now = s.Substring(i, 1);
                i++;

                int cnt = 1;

                if (i == s.Length)
                {
                    if (now == "<") sb.Append("<" + cnt);
                    else sb.Append(">" + cnt);
                    break;
                }

                while (now == s[i].ToString())
                {
                    cnt++;
                    i++;
                    if (i == s.Length) break;
                }
                if (now == "<") sb.Append("<" + cnt);
                else sb.Append(">" + cnt);
            }
            return sb.ToString();
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}