str_0 = input()
N = 0
while 1:
p = str_0.find('P')
if p == -1:
break
P_num = 1
while p < len(str_0) -1 and str_0[p+1] == 'P':
p += 1
P_num += 1
T = str_0[p + 1:].find('T')
t = T + len(str_0[:p + 1])
n = 0
while T != -1 and t < len(str_0):
T_num = 1
while t < len(str_0) - 1 and str_0[t+1] == 'T':
t += 1
T_num += 1
A_num = str_0[p:t].count('A')
n += T_num * A_num
t += 1
T = str_0[t:].find('T')
t = T + len(str_0[:t])
N += n*P_num
str_0 = str_0[p+1:]
print(N % 1000000007)