https://www.patest.cn/contests/pat-b-practise/1040
#include "stdio.h" int main() { int p = 0, a = 0, t = 0; char c; while(scanf("%c", &c) && (' ' != c)) { if('P' == c) ++p; else if('A' == c) a += p; else if('T' == c) t = (t + a) % 1000000007; } printf("%d ", t); return 0; }