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 JavaScript (node.js v5.12) (judge verdict: Wrong Answer)

function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  var counter = new Array(input.length+1);
  input = myconv(input,6);
  var indexX = [];
  var indexZero = [];
  if(input[0] == "<"){
     counter[0] = 0;
    indexZero.push(0);
  }else{
     counter[0] = "x";
    indexX.push(0);
  }
  
  for(var i = 1; i < input.length; i++){
    var mae = input[i-1];
    var ato = input[i];
    if(mae == ">" && ato == "<"){
       counter[i] = 0;
      indexZero.push(i);
    }else if(mae == "<" && ato == ">"){
       counter[i] = "x";      
      indexX.push(i);
	}
  }
  
  if(input[input.length-1] == ">"){
     counter[input.length] = 0;
    indexZero.push(input.length);
  }else{
    counter[input.length] = "x";
    indexX.push(input.length);
  }
  /*myout("x:" + indexX);
  myout("0:" + indexZero);
  myout(counter);*/
  var sum = 0;
  if(indexX.length > indexZero.length){
       var tmp = indexX;
       indexX = indexZero;
    indexZero = tmp;
	}else if(indexX.length == indexZero.length){
        if(indexX[0] == 0){
           indexZero.unshift(-1);
           }else{
           indexZero.push(indexX[indexX.length-1]+1);
           }
    }
  
  //myout("x:" + indexX);
  //myout("0:" + indexZero);
  for(var i = 0; i < indexX.length; i++){
    var index = indexX[i];
    var mae = index - indexZero[i];
    var ato = indexZero[i+1] - index;
    if(mae > ato){
       counter[index] = mae;
      sum += (mae*(mae+1)/2) + ((ato-1)*(ato)/2);
    }else if(mae < ato){
         counter[index] = ato;
      sum += (ato*(ato+1)/2) + ((mae-1)*(mae)/2);
    }else{
      counter[index] = ato;
      sum += (ato*(ato+1)/2) + ((mae-1)*(mae)/2);
    }
  }
  //myout(counter);
  myout(sum);
}

Main(myin());