#!/usr/bin/env python3 import sys G = [] def get(i, j): if i >= 0 and i < len(G) and j >= 0 and j < len(G[0]): return G[i][j] return "" # Read the puzzle for l in sys.stdin: letts = [c for c in l.strip()] G.append(letts) c = 0 for i in range(len(G)): for j in range(len(G[0])): chk = lambda di, dj: get(i+di,j+dj) == "M" and get(i+2*di,j+2*dj) == "A" and get(i+3*di,j+3*dj) == "S" if G[i][j] == "X": c += chk(1, 1) c += chk(1, 0) c += chk(1, -1) c += chk(0, 1) c += chk(0, -1) c += chk(-1, 1) c += chk(-1, 0) c += chk(-1, -1) print(c)