#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 500010;
int n;
char str[N];
int l[N], r[N];
int main()
{
scanf("%d%s", &n, str);
for (int i = 0, sh = 0, sg = 0; i < n; i ++ )
if (str[i] == 'G') l[i] = sh, sg ++, sh = 0;
else l[i] = sg, sh ++, sg = 0;
for (int i = n - 1, sh = 0, sg = 0; i >= 0; i -- )
if (str[i] == 'G') r[i] = sh, sg ++, sh = 0;
else r[i] = sg, sh ++, sg = 0;
LL res = 0;
for (int i = 0; i < n; i ++ )
res += (LL)l[i] * r[i] + max(r[i] - 1, 0) + max(l[i] - 1, 0);
printf("%lld\n", res);
return 0;
}
4261. 孤独的照片 贡献法 乘法原理
最新推荐文章于 2024-08-30 15:57:36 发布