from itertools import islice from sys import stdin mat = tuple(map(str.strip, stdin.readlines())) m = len(mat) n = len(mat[0]) print(sum(c == 'A' and ({mat[i-1][j-1], mat[i+1][j+1]} == {mat[i-1][j+1], mat[i+1][j-1]} == {'M', 'S'}) for i, line in islice(enumerate(mat), 1, m-1) for j, c in islice(enumerate(line), 1, n-1)))