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 Rust (1.42.0) (judge verdict: Wrong Answer)

use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn rle(s: Vec<char>) -> Vec<(char, u64)> {
    let mut res: Vec<(char, u64)> = Vec::new();
    let mut pre = ' ';
    let mut chain = 1;

    for c in s.into_iter() {
        if c == pre {
            chain += 1;
        } else {
            if pre != ' ' {
                res.push((pre, chain));
            }
            pre = c;
            chain = 1;
        }
    }
    res.push((pre, chain));
    res
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let rle = rle(s);
    let mut ans = 0;
    println!("{:?}", rle);

    //先端の処理
    if rle[0].0 == '>' {
        ans += (rle[0].1 * (rle[0].1 + 1)) / 2;
    }
    let mid_ans: u64 = rle[..]
        .windows(2)
        .map(|v| {
            let mut res = 0;
            if v[0].0 == '<' && v[1].0 == '>' {
                if v[0].1 >= v[1].1 {
                    res += (v[0].1 * (v[0].1 + 1)) / 2;
                    res += (v[1].1 * (v[1].1 - 1)) / 2;
                }else{
                    res += (v[0].1 * (v[0].1 - 1)) / 2;
                    res += (v[1].1 * (v[1].1 + 1)) / 2;
                }
            }
            res
        })
        .sum();
    //println!("{}", mid_ans);
    ans += mid_ans;
    //終端の処理
    if let Some(v) = rle.last() {
        if v.0 == '<' {
            ans += (v.1 * (v.1 + 1)) / 2;
        }
    }

    println!("{}", ans);
}