Populate forces going from left to right
int f = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' R ' ) { f = N ; } else if ( S [ i ] == ' L ' ) { f = 0 ; } else { f = max ( f - 1 , 0 ) ; } force [ i ] += f ; }