#include<stdio.h>
const int N = 1000000007;
char s[100010];
int count[2][100010];
int main() {
scanf("%s",s);
int i=0,num=0;
while(s[i]!='\0') {
if(s[i]=='P') num++;
if(s[i]=='A') count[0][i]=num;
++i;
}
int len=i;
--i;
num=0;
while(i>-1) {
if(s[i]=='T') num++;
if(s[i]=='A') count[1][i]=num;
--i;
}
int re=0;
for(i=0; i<len; ++i) {
re+=count[0][i]*count[1][i];
re=re%N;
}
printf("%d",re);
// for(i=0; i<len; ++i) printf("%d ",count[0][i]);
// printf("\n");
// for(i=0; i<len; ++i) printf("%d ",count[1][i]);
// printf("\n");
return 0;
}