Cheating and Stealing
题号:NC222401
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Gromah is playing PingPong with PJ King. However, Gromah is poor at PingPong and it's difficult for him to beat PJ King in the normal way. So Gromah has to cheat and steal, which is to let PJ King send some points and then change the winning points in one game after the end of the match.

Gromah and PJ King have played times totally, and the results were all recorded as a string only containing "W"(denoting Gromah wins this point) and "L"(denoting PJ King wins this point). Now Gromah wants to know that for all , how many games he can win if the winning point equals in one game(denoted by f_i(S)), and you can determine f_i(S) in following procedure:

(1). Check if there is any prefix in current satisfying where cnt_W, cnt_L denotes the number of "W"s and "L"s in the prefix respectively.
(2). If no such prefix exists, terminate the procedure regardless of the remaining results.
(3). If exists, choose the shortest prefix among all valid prefixes(denoting one game), and add 1 to f_i(S) iff . Then remove the chosen prefix from and turn back to step (1).

Since the output is too large, you should only print one integer .

输入描述:

The first line contains one integer , denoting the length of the string .

The second line contains one string of length , which only contains "W" and "L".

输出描述:

Output one line containing only one integer, denoting the answer.
示例1

输入

复制
9
LWWWLLWLL

输出

复制
111

说明

f_1(S) = 1, Gromah wins one game("LWWW"), then PJ King wins one game("LL"), and "WLL" remains.
f_2(S) = 1, Gromah wins one game("LWWW"), then PJ King wins one game("LL"), and "WLL" remains.
f_3(S) = 1, Gromah wins one game("LWWW"), then PJ King wins one game("LLWL"), and "L" remains.
f_4(S) = f_5(S) = f_6(S) = f_7(S) = f_8(S) = f_9(S) = 0, no game finished.

So the answer equals 1 \times (9+1)^0 + 1 \times (9+1)^1 + 1\times (9+1)^2 = 1 + 10 + 100 = 111.