#include <iostream>
#include <cstring>
using namespace std;
const int mod = 1000000007;
long long p, a, b, ans;
int main(){
string str;
cin >> str;
for(int i = 0; i < str.size(); i++)
if(str[i] == 'P') p ++;
else if(str[i] == 'A') a += p;
else ans = (ans + a) % mod;
cout<<ans<<endl;
return 0;
}