# 【cf399B】Red and Blue Balls

## 描述 Description

User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.

While the top ball inside the stack is red, pop the ball from the top of the stack.

Then replace the blue ball on the top with a red ball.

And finally push some blue balls to the stack until the stack has total of n balls inside.

If there are no blue balls inside the stack, ainta can’t apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.

## 输入格式 InputFormat

The first line contains an integer n (1 ≤ n ≤ 50) — the number of balls inside the stack.
The second line contains a string s (|s| = n) describing the initial state of the stack. The i-th character of the string s denotes the color of the i-th ball (we’ll number the balls from top to bottom of the stack). If the character is“R”, the color is red. If the character is“B”, the color is blue.

## 输出格式 OutputFormat

Print the maximum number of operations ainta can repeatedly apply.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

5
RBBRR

6

Codeforces 399B

## 代码 Code

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
char ch[100];
long long a[100];
int i,j,t,n,m,l,r,k,z,y,x;
long long ans;
int main()
{
scanf("%d",&n);
a[0]=1;
for (i=1;i<n;i++) a[i]=a[i-1]*2;
scanf("%s",ch);
ans=0;
for (i=0;i<strlen(ch);i++) if (ch[i]=='B') ans+=a[i];
printf("%I64d",ans);
return 0;
}