#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf = 1000000007;
int l[100010] = {0},r[100010] = {0};
char s[100010];
int main()
{
int sum = 0;
scanf("%s",s);
int len = strlen(s);
for(int i = 0; i < len; i++)
{
if(i != 0)
l[i] = l[i-1];
if(s[i] == 'P')
{
l[i]++;
}
}
for(int i = len-1; i >= 0; i--)
{
if(i != len-1)
r[i] = r[i+1];
if(s[i] == 'T')
{
r[i]++;
}
}
for(int i = 0; i < len; i++)
{
if(s[i] == 'A')
sum = (sum + r[i] * l[i]) % inf;
}
printf("%d",sum);
return 0;
}