Betting game
Submissions: 6346   Accuracy:

27.57%

  Difficulty: Medium   Marks: 4

You are involved in a betting game whose rules are as follows :
a) If you win a round, the bet amount will be added to your current sum and next bet amount will become $1;
b) If you lose a round, the bet amount will be reduced from your current sum and next bet will become twice the previous.
c) game ends either when all the rounds are complete or when you don't have sufficient sum.
Initially, you are given with a string consisiting of characters from the set {'W', 'L'}, where 'W' indicates a win and 'L' indicates a loss, and initial sum is 4. Initial bet amount for the 1st round will be $1.

You need to find and print the amount at the end of the game (final sum) and in case you do not have enough money in between the game to play the next round, then print -1.

Input:

The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is a string S made of {W,L}.

Output:

Print the amount at the end of the game (final sum) and in case you have not enough money in between the game then print -1.

Constraints:

1 ≤ T ≤ 100
1 ≤ Size of string S ≤ 50

Example:

Input:
2
WL
WLWLLLWWLW

Output:
4
-1

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.