代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
string str;
cin >> str;
int len = str.length();
int res = 0;
vector<int> p(len);
vector<int> t(len);
for (int i = 0; i <= len- 2; i++) {
if (str[i] == 'P') {
p[i + 1] = p[i] + 1;
}
else {
p[i + 1] = p[i];
}
}
for (int i = len - 1; i >= 1; i--) {
if (str[i] == 'T') {
t[i - 1] = t[i] + 1;
}
else {
t[i - 1] = t[i];
}
}
for (int i = 0; i < len; i++) {
if (str[i] == 'A') {
res = (res+ p[i] * t[i]) % 1000000007;
}
}
printf("%d", res);
}