import sys, os L = sys.stdin.read().strip().split("\n") G = [list(l) for l in L] H = len(G) W = len(G[0]) M4 = [(0,1),(0,-1),(1,0),(-1,0)] D4 = [(1,1),(-1,-1),(1,-1),(-1,1)] M8 = M4 + D4 S = 0 for i in range(H): # rows for j in range(W): # cols if G[i][j] == "X": for (dx,dy) in M8: xi = i yj = j for l in 'MAS': xi += dx yj += dy if xi<0 or xi>=H or yj<0 or yj>=W or G[xi][yj]!=l: break else: # if the inner loop wasn't broken. S += 1 print(S)