#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
cin>>s;
long p = 0,a = 0,t = 0;
for(int i = s.size()-1;i>=0;i--)
{
if(s[i] == 'T')
{
t++;
}
else if(s[i] == 'A')
{
a+=t;
}
else if(s[i] == 'P')
{
p+=a;
}
}
cout<<p%1000000007<<endl;
return 0;
}