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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.awt.Point;
import java.util.function.*;
import java.util.*;
import java.io.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1234567;
    static int inf = 0x7ffffff;

    public static void main(String[]$) throws Exception {
        String s = scanner.next();
        int n = s.length();
        Map<Integer, Integer> a = new HashMap<>();
        Map<Integer, Integer> b = new HashMap<>();
        Deque<Point> deque = new ArrayDeque<>();
        for (int i = 0; i <= n; i++) {
            if ((i == 0 || s.charAt(i - 1) == '>') && (i == n || s.charAt(i) == '<')) {
                deque.addLast(new Point(0, i));
            }
        }
        int last = -1;
        while (!deque.isEmpty()) {
            Point p = deque.poll();
            if (last < p.x) {
                a = new HashMap<>(b);
                b.clear();
            }
            int i = p.y;
            int m = Math.max(a.getOrDefault(i - 1, -1), a.getOrDefault(i + 1, -1)) + 1;
            if (a.getOrDefault(i, -1) < m) {
                b.put(i, m);
                if (0 < i && s.charAt(i - 1) == '>') {
                    deque.add(new Point(m + 1, i - 1));
                }
                if (i < n && s.charAt(i) == '<') {
                    deque.add(new Point(m + 1, i + 1));
                }
            }
            last = m;
        }
        System.out.println(b.values().stream().mapToInt(Integer::intValue).sum());
    }

    static class System {
        static PrintWriter out = new PrintWriter(java.lang.System.out);

        static {
            Runtime.getRuntime().addShutdownHook(new Thread(System.out::flush));
        }

        static void exit() {
            java.lang.System.exit(0);
        }
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        char[][] nextCharArray(int n, int m) {
            char[][] a = new char[n][m];
            for (int i = 0; i < n; i++) {
                a[i] = next().toCharArray();
            }
            return a;
        }
        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        int[] nextIntArray(int n, IntUnaryOperator op) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsInt(nextInt());
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        long[] nextLongArray(int n, LongUnaryOperator op) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = op.applyAsLong(nextLong());
            }
            return a;
        }
    }
}