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.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let n = s.len() + 1;
    let mut span = vec![2i64];
    for i in 1..s.len() {
        if s[i] == s[i - 1] {
            let last_idx = span.len() - 1;
            span[last_idx] += 1;
        } else {
            span.push(2);
        }
    }

    let mut accum = vec![0; n + 1];
    for i in 1..n + 1 {
        accum[i] = accum[i - 1] + i as i64;
    }

    let mut ans = 0i64;
    for &num in span.iter() {
        ans += accum[num as usize - 2];
    }
    for i in 1..span.len() {
        if i % 2 == 1 && s[0] == '<' {
            ans += max(span[i], span[i - 1]) - 1;
        } else if i % 2 == 0 && s[0] == '>' {
            ans += max(span[i], span[i - 1]) - 1;
        }
    }
    if s[s.len() - 1] == '<' {
        ans += span[span.len() - 1] - 1;
    }
    if s[0] == '>' {
        ans += span[0] - 1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}