#https://inf-ege.sdamgia.ru/problem?id=59686
alph = 'АГМНСТУ'
ind = 0
for q in alph:
for w in alph:
for e in alph:
for r in alph:
for t in alph:
for y in alph:
ind += 1
s = q + w + e + r + t + y
if s[0] != 'У' and s.count('М') == 2 and s.count('Г') <= 1:
print(ind)