AC (7ms, 552KB)
|
CPP
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
vector<long long int> v;
int n=0;
for(auto i:s)
{
if(i=='Q') n++;
else if(i=='A') v.push_back(n),n=0;
}
v.push_back(n);
long long int l[v.size()];
l[v.size()-1]=v[v.size()-1];
for(int i=v.size()-2;i>=0;i--)
{
l[i]=v[i]+l[i+1];
}
//for(auto i:v) cout<<i<<" ";
//cout<<"\n";
//for(auto i:l) cout<<i<<" ";
//cout<<"\n";
long long int num=0;
for(int i=1;i<v.size();i++)
{
num+=v[i-1]*l[i];
v[i]+=v[i-1];
}
cout<<num<<"\n";
}
}