Populate forces going from right to left
f = 0 NEW_LINE for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if S [ i ] == ' L ' : NEW_LINE INDENT f = N NEW_LINE DEDENT elif S [ i ] == ' R ' : NEW_LINE INDENT f = 0 NEW_LINE DEDENT else : NEW_LINE INDENT f = max ( f - 1 , 0 ) NEW_LINE DEDENT force [ i ] -= f NEW_LINE DEDENT