The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. 

In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face". 

You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.


-----Input-----

The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.

Next n lines define the image. Each line contains m lowercase Latin letters.


-----Output-----

In the single line print the number of faces on the image.


-----Examples-----
Input
4 4
xxxx
xfax
xcex
xxxx

Output
1

Input
4 2
xx
cf
ae
xx

Output
1

Input
2 3
fac
cef

Output
2

Input
1 4
face

Output
0



-----Note-----

In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:  [Image] 

In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.

In the third sample two faces are shown:  $\text{fac}$ 

In the fourth sample the image has no faces on it.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation


Solutions:
(n, m) = map(int, input().split())
a = [list(input()) for i in range(n)]
d = set(['f', 'a', 'c', 'e'])
k = 0
for i in range(n - 1):
	for j in range(m - 1):
		if a[i][j] in d:
			s = set()
			s.add(a[i][j])
			s.add(a[i + 1][j])
			s.add(a[i + 1][j + 1])
			s.add(a[i][j + 1])
			if s == d:
				k += 1
print(k)


(n, m) = list(map(int, input().split()))
field = []
for i in range(n):
	field.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		t = set()
		t.add(field[i][j])
		t.add(field[i + 1][j + 1])
		t.add(field[i + 1][j])
		t.add(field[i][j + 1])
		if t == set('face'):
			ans += 1
print(ans)


(a, b) = map(int, input().split())
l = []
p = 0
for m in range(a):
	lPrime = list(input())
	l.append(lPrime)
for q in range(0, a - 1):
	for w in range(0, b - 1):
		if l[q][w] not in ['f', 'a', 'c', 'e', 1, 100, 150, 5]:
			l[q][w] = 0
		if l[q][w + 1] not in ['f', 'a', 'c', 'e', 1, 100, 150, 5]:
			l[q][w + 1] = 0
		if l[q + 1][w] not in ['f', 'a', 'c', 'e', 1, 100, 150, 5]:
			l[q + 1][w] = 0
		if l[q + 1][w + 1] not in ['f', 'a', 'c', 'e', 1, 100, 150, 5]:
			l[q + 1][w + 1] = 0
		if l[q][w] == 'f':
			l[q][w] = 1
		if l[q][w + 1] == 'f':
			l[q][w + 1] = 1
		if l[q + 1][w] == 'f':
			l[q + 1][w] = 1
		if l[q + 1][w + 1] == 'f':
			l[q + 1][w + 1] = 1
		if l[q][w] == 'a':
			l[q][w] = 100
		if l[q][w + 1] == 'a':
			l[q][w + 1] = 100
		if l[q + 1][w] == 'a':
			l[q + 1][w] = 100
		if l[q + 1][w + 1] == 'a':
			l[q + 1][w + 1] = 100
		if l[q][w] == 'c':
			l[q][w] = 150
		if l[q][w + 1] == 'c':
			l[q][w + 1] = 150
		if l[q + 1][w] == 'c':
			l[q + 1][w] = 150
		if l[q + 1][w + 1] == 'c':
			l[q + 1][w + 1] = 150
		if l[q][w] == 'e':
			l[q][w] = 5
		if l[q][w + 1] == 'e':
			l[q][w + 1] = 5
		if l[q + 1][w] == 'e':
			l[q + 1][w] = 5
		if l[q + 1][w + 1] == 'e':
			l[q + 1][w + 1] = 5
for i in range(0, a - 1):
	for j in range(0, b - 1):
		u = l[i][j] + l[i][j + 1] + l[i + 1][j] + l[i + 1][j + 1]
		if u == 256:
			p = p + 1
print(p)


(n, m) = map(int, input().split())
im = []
w = 0
for i in range(n):
	im.append(list(input()))
if n == 1 or m == 1:
	print(0)
	quit()
for i in range(n - 1):
	for j in range(m - 1):
		x = [im[i][j], im[i][j + 1], im[i + 1][j], im[i + 1][j + 1]]
		x.sort()
		if x == ['a', 'c', 'e', 'f']:
			w += 1
print(w)


import sys

def solve():
	(n, m) = map(int, input().split())
	tab = [list(input()) for x in range(n)]
	need = set(['f', 'a', 'c', 'e'])
	res = 0
	for row in range(n - 1):
		for col in range(m - 1):
			s = set()
			for r in range(row, row + 2):
				for c in range(col, col + 2):
					s.add(tab[r][c])
			if need.issubset(s):
				res += 1
	return res

def run():
	if sys.hexversion == 50594544:
		sys.stdin = open('test.txt')
	print(solve())
run()


(n, m) = map(int, input().split())
if n == 1 or m == 1:
	print(0)
	quit()
s_f = set(['f', 'a', 'c', 'e'])
t = 0
l_p = list()
for i in range(n):
	l_p.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		s_s = set([l_p[i][j], l_p[i + 1][j], l_p[i][j + 1], l_p[i + 1][j + 1]])
		if s_s == s_f:
			t += 1
print(t)


(n, m) = map(int, input().split())
image = []
for _ in range(n):
	image.append(input())
n_images = 0
for i in range(n - 1):
	for j in range(m - 1):
		face = image[i][j:j + 2] + image[i + 1][j:j + 2]
		if 'f' in face and 'a' in face and ('c' in face) and ('e' in face):
			n_images += 1
print(n_images)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	x = [i for i in input()]
	a.append(x)
count = 0
for j in range(m - 1):
	for i in range(n - 1):
		x = set([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]])
		if x == {'a', 'f', 'c', 'e'}:
			count += 1
print(count)


(r, c) = map(int, input().split())
l = [[c for c in input()] for _ in range(r)]
total = 0
f = set((c for c in 'face'))
for x in range(r - 1):
	for y in range(c - 1):
		if l[x][y] in 'face':
			total += {l[x][y], l[x][y + 1], l[x + 1][y], l[x + 1][y + 1]} == f
print(total)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
c = 0
for i in range(n - 1):
	for j in range(m - 1):
		c += sorted(a[i][j:j + 2] + a[i + 1][j:j + 2]) == sorted('face')
print(c)


(n, m) = input().split()
n = int(n)
m = int(m)
matriz = [None] * n
for i in range(n):
	matriz[i] = str(input())
count = 0
for i in range(n):
	for j in range(m):
		try:
			string = matriz[i][j] + matriz[i + 1][j] + matriz[i][j + 1] + matriz[i + 1][j + 1]
			if 'f' in string and 'a' in string and ('c' in string) and ('e' in string):
				count += 1
		except IndexError:
			pass
print('%d' % count)


(n, m) = map(int, input().split())
matrix = [[i for i in input()] for j in range(n)]
array = []
counter = 0
for i in range(len(matrix) - 1):
	for j in range(len(matrix[i])):
		if j > 0 and i != len(matrix) - 1:
			array.append([matrix[i][j - 1], matrix[i][j], matrix[i + 1][j - 1], matrix[i + 1][j]])
for i in array:
	if i.count('f') == 1 and i.count('a') == 1 and (i.count('c') == 1) and (i.count('e') == 1):
		counter += 1
print(counter)


(n, m) = map(int, input().split())
li = []
total = 0
li1 = ['f', 'a', 'c', 'e']
for i1 in range(n):
	li.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		if li[i][j] in li1:
			if li[i][j + 1] in li1 and li[i][j + 1] != li[i][j]:
				if li[i + 1][j] in li1 and li[i + 1][j] != li[i][j] and (li[i + 1][j] != li[i][j + 1]):
					if li[i + 1][j + 1] in li1 and li[i + 1][j + 1] != li[i][j] and (li[i + 1][j + 1] != li[i + 1][j]) and (li[i + 1][j + 1] != li[i][j + 1]):
						total += 1
print(total)


import sys
(m, n) = map(int, input().split())
img = []
for _ in range(m):
	img.append(list(input()))
count = 0
if m < 2 or n < 2:
	print(0)
	sys.exit(0)
for i in range(m - 1):
	for j in range(n - 1):
		f = [img[i][j], img[i + 1][j], img[i][j + 1], img[i + 1][j + 1]]
		if 'f' in f and 'a' in f and ('c' in f) and ('e' in f):
			count += 1
print(count)


def face_found(l):
	f1 = f2 = f3 = f4 = 0
	for ii in l:
		if ii == 'f':
			f1 += 1
		if ii == 'a':
			f2 += 1
		if ii == 'c':
			f3 += 1
		if ii == 'e':
			f4 += 1
	if f1 == f2 == f3 == f4 == 1:
		return 1
	else:
		return 0
(n, m) = map(int, input().split(' '))
o = 0
ll = []
for i in range(n):
	l = list(input())
	ll.append(l)
for i in range(n - 1):
	for ii in range(m - 1):
		p = [ll[i][ii], ll[i + 1][ii], ll[i][ii + 1], ll[i + 1][ii + 1]]
		if face_found(p):
			o += 1
print(o)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(input()))
cnt = 0
check = ['f', 'a', 'c', 'e']
check.sort()
arr2 = []
for i in range(n - 1):
	for j in range(m - 1):
		arr2 = [arr[i][j]] + [arr[i][j + 1]] + [arr[i + 1][j]] + [arr[i + 1][j + 1]]
		arr2.sort()
		if arr2 == check:
			cnt += 1
print(cnt)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

def VI():
	return list(map(int, input().split()))

def main(n, m, im):
	ans = 0
	if n == 1 or m == 1:
		print(ans)
		return

	def detect(x):
		if len(x) < 4:
			return 0
		if 'f' in x and 'a' in x and ('c' in x) and ('e' in x):
			return 1
		return 0
	for i in range(n):
		for j in range(m):
			if im[i][j] == 'f':
				if i > 0 and j > 0:
					ans += detect(im[i - 1][j - 1:j + 1] + im[i][j - 1:j + 1])
				if i < n - 1 and j > 0:
					ans += detect(im[i][j - 1:j + 1] + im[i + 1][j - 1:j + 1])
				if i > 0 and j < m - 1:
					ans += detect(im[i - 1][j:j + 2] + im[i][j:j + 2])
				if i < n - 1 and j < m - 1:
					ans += detect(im[i][j:j + 2] + im[i + 1][j:j + 2])
	print(ans)

def main_input(info=0):
	(n, m) = VI()
	im = list(range(n))
	for i in range(n):
		im[i] = input()
	main(n, m, im)
main_input()


(n, m) = map(int, input().split())
M = [input() for i in range(n)]
k = 0
L = sorted('face')
for i in range(n):
	for j in range(m):
		F = ''
		if i + 2 <= n and j + 2 <= m:
			F = F + M[i][j] + M[i][j + 1] + M[i + 1][j] + M[i + 1][j + 1]
		if sorted(F) == L:
			k = k + 1
print(k)


import sys
input = []
input_index = 0

def next(type, number=None):

	def next():
		nonlocal input, input_index
		while input_index == len(input):
			if sys.stdin:
				input = sys.stdin.readline().split()
				input_index = 0
			else:
				raise Exception()
		input_index += 1
		return input[input_index - 1]
	if number is None:
		result = type(next())
	else:
		result = [type(next()) for _ in range(number)]
	return result
(n, m) = next(int, 2)
iis = [next(str) for _ in range(n)]
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = {iis[i][j], iis[i + 1][j], iis[i][j + 1], iis[i + 1][j + 1]}
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			count += 1
print(count)


(n, m) = (int(i) for i in input().split())
ref = set('face')
data = []
face = 0
for i in range(n):
	data.append(input())
for i in range(n):
	for j in range(m):
		if data[i][j] == 'f':
			if i < n - 1 and j < m - 1:
				test = set(data[i][j] + data[i + 1][j] + data[i + 1][j + 1] + data[i][j + 1])
				if test == ref:
					face += 1
			if i > 0 and j < m - 1:
				test = set(data[i][j] + data[i - 1][j] + data[i - 1][j + 1] + data[i][j + 1])
				if test == ref:
					face += 1
			if i > 0 and j > 0:
				test = set(data[i][j] + data[i - 1][j] + data[i - 1][j - 1] + data[i][j - 1])
				if test == ref:
					face += 1
			if i < n - 1 and j > 0:
				test = set(data[i][j] + data[i + 1][j] + data[i + 1][j - 1] + data[i][j - 1])
				if test == ref:
					face += 1
print(face)


(n, m) = map(int, input().split())
img = [input() for _ in range(n)]
print(sum(({img[i][j], img[i][j + 1], img[i + 1][j], img[i + 1][j + 1]} == set('face') for i in range(n - 1) for j in range(m - 1))))


(n, m) = str(input()).split(' ')
n = int(n)
m = int(m)
matrix = []
for i in range(n):
	matrix.append(list(input()))
counter = 0
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] == 'f' or matrix[i][j] == 'a' or matrix[i][j] == 'c' or (matrix[i][j] == 'e'):
			word = matrix[i][j]
			if matrix[i][j + 1] == 'f' or matrix[i][j + 1] == 'a' or matrix[i][j + 1] == 'c' or (matrix[i][j + 1] == 'e'):
				word += matrix[i][j + 1]
				if matrix[i + 1][j] == 'f' or matrix[i + 1][j] == 'a' or matrix[i + 1][j] == 'c' or (matrix[i + 1][j] == 'e'):
					word += matrix[i + 1][j]
					if matrix[i + 1][j + 1] == 'f' or matrix[i + 1][j + 1] == 'a' or matrix[i + 1][j + 1] == 'c' or (matrix[i + 1][j + 1] == 'e'):
						word += matrix[i + 1][j + 1]
						if 'f' in word and 'a' in word and ('c' in word) and ('e' in word):
							counter += 1
print(counter)


(n, m) = map(int, input().split())
l = []
c = 0
for i in range(n):
	l.append(list(input()))
for i in range(n - 1):
	for j in range(m - 1):
		x = [l[i][j], l[i + 1][j], l[i][j + 1], l[i + 1][j + 1]]
		x.sort()
		if x == list('acef'):
			c += 1
print(c)


(n, m) = list(map(int, input().split()))
ans = 0
A = [input() for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if sorted(A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1]) == sorted('face'):
			ans += 1
print(ans)


(n, m) = map(int, input().split())
g = []
for _ in range(n):
	g.append(input())
if n < 2 or m < 2:
	print(0)
	exit()
ans = 0
for i in range(0, n - 1):
	for j in range(0, m - 1):
		l = sorted([g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]])
		if ''.join(l) == 'acef':
			ans += 1
print(ans)


(n, m) = [int(x) for x in input().split()]
if n < 2 or m < 2:
	print(0)
	quit()
c = 0
mas = []
for i in range(n):
	mas.append(input())
f = set('face')
for i in range(n - 1):
	for j in range(m - 1):
		k = set()
		k.add(mas[i][j])
		k.add(mas[i + 1][j])
		k.add(mas[i][j + 1])
		k.add(mas[i + 1][j + 1])
		if len(k & f) == 4:
			c += 1
print(c)


(x, y) = map(int, input().split())
tot = 0
table = []
for i in range(x):
	table.append(input())
if x == 1 or y == 1:
	print(tot)
else:
	for i in range(x - 1):
		for j in range(y - 1):
			string = table[i][j:j + 2] + table[i + 1][j:j + 2]
			if 'f' in string and 'a' in string and ('c' in string) and ('e' in string):
				tot += 1
	print(tot)


from itertools import permutations
(x, y) = map(int, input().split())
l = {'f', 'a', 'c', 'e'}
perm = permutations('face')
list1 = list(perm)
count = 0
arr = []
for i in range(x):
	t = input()
	arr.append(t)
for i in range(x - 1):
	for j in range(y - 1):
		t = (arr[i][j], arr[i + 1][j], arr[i][j + 1], arr[i + 1][j + 1])
		if t in list1:
			count = count + 1
print(count)


(r, c) = [int(i) for i in input().split()]
T = []
Q = 0
for i in range(r):
	T.append(input())
for R in range(r - 1):
	for C in range(c - 1):
		if ''.join(sorted([T[R][C], T[R + 1][C], T[R + 1][C + 1], T[R][C + 1]])) == 'acef':
			Q += 1
print(Q)


(n, m) = [int(x) for x in input().split()]
image = []
for i in range(n):
	image.append(list(input()))
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		det = ['f', 'a', 'c', 'e']
		if image[i][j] in det:
			det.remove(image[i][j])
		if image[i + 1][j] in det:
			det.remove(image[i + 1][j])
		if image[i][j + 1] in det:
			det.remove(image[i][j + 1])
		if image[i + 1][j + 1] in det:
			det.remove(image[i + 1][j + 1])
		if len(det) == 0:
			ans += 1
print(ans)


A = []
dx = [0, 0, 1, 1]
dy = [0, 1, 0, 1]

def fun(a, b):
	c = {'f': 1, 'a': 1, 'c': 1, 'e': 1}
	ans = 0
	for i in range(4):
		if A[a + dx[i]][b + dy[i]] in c:
			ans = ans + c[A[a + dx[i]][b + dy[i]]]
			c[A[a + dx[i]][b + dy[i]]] = 0
	return ans == 4
(n, m) = [int(s) for s in input().split()]
for i in range(n):
	A.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if fun(i, j):
			ans += 1
print(ans)


(rows, cols) = map(int, input().split())
faces = 0
prev = input()
for row in range(rows - 1):
	curr = input()
	for col in range(cols - 1):
		if sorted(prev[col] + prev[col + 1] + curr[col] + curr[col + 1]) == sorted('face'):
			faces += 1
	prev = curr
print(faces)


(n, m) = map(int, input().strip().split())
s = []
for i in range(n):
	In = input()
	tmp = []
	for c in In:
		tmp.append(c)
	s.append(tmp)
ans = 0
tot = 0
dict = {}
for i in range(n - 1):
	for j in range(m - 1):
		dict.clear()
		dict[s[i][j]] = 1
		dict[s[i + 1][j]] = 1
		dict[s[i][j + 1]] = 1
		dict[s[i + 1][j + 1]] = 1
		if 'f' in dict and 'a' in dict and ('c' in dict) and ('e' in dict):
			ans = ans + 1
print(ans)


(n, m) = map(int, input().split())
x = []
for a in range(n):
	x.append(input())
faces = 0
for i in range(0, n - 1):
	for j in range(0, m - 1):
		f = []
		f.append(x[i][j])
		f.append(x[i][j + 1])
		f.append(x[i + 1][j])
		f.append(x[i + 1][j + 1])
		f = sorted(f)
		if ''.join(f) == 'acef':
			faces += 1
print(faces)


(n, m) = map(eval, input().split())
l = []
lf = []

def perm(a, k=0):
	if k == len(a):
		lf.append(''.join(a))
	else:
		for i in range(k, len(a)):
			(a[k], a[i]) = (a[i], a[k])
			perm(a, k + 1)
			(a[k], a[i]) = (a[i], a[k])
perm(['f', 'a', 'c', 'e'])
ans = 0
for i in range(n):
	l.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		if l[i][j] + l[i + 1][j] + l[i][j + 1] + l[i + 1][j + 1] in lf:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
inp = []
for _ in range(n):
	inp.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		a = ''
		a += inp[i][j]
		a += inp[i][j + 1]
		a += inp[i + 1][j]
		a += inp[i + 1][j + 1]
		a = list(a)
		a.sort()
		if a == ['a', 'c', 'e', 'f']:
			ans += 1
print(ans)


(r, c) = map(int, input().split())
l = [input() for _ in range(r)]
t = 0
for x in range(r - 1):
	for y in range(c - 1):
		z = l[x][y:y + 2] + l[x + 1][y:y + 2]
		if all((i in z for i in ['f', 'a', 'c', 'e'])):
			t += 1
print(t)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = {a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]}
		if s == set('face'):
			cnt += 1
print(cnt)


(n, m) = [int(x) for x in input().split(' ')]
grid = [input() for row in range(n)]
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if set([grid[i][j], grid[i + 1][j], grid[i + 1][j + 1], grid[i][j + 1]]) == set(['f', 'a', 'c', 'e']):
			count += 1
print(count)


X = list(map(int, input().split()))
Face = 'face'
Count = 0
Prev = input()
for i in range(X[0] - 1):
	Curr = input()
	for j in range(len(Curr) - 1):
		Temp = set(Curr[j] + Curr[j + 1] + Prev[j] + Prev[j + 1])
		Count += 1 if len(Temp) == 4 and all([True if c in Face else False for c in Temp]) else 0
	Prev = Curr
print(Count)


import itertools
import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	(n, m) = input_ints()
	s = []
	for i in range(n):
		s.append(input())
	c = sorted(list('face'))
	ans = 0
	for (i, j) in itertools.product(range(n - 1), range(m - 1)):
		x = [s[i][j], s[i + 1][j], s[i][j + 1], s[i + 1][j + 1]]
		if sorted(x) == c:
			ans += 1
	print(ans)
solve()


(n, m) = map(int, input().split())
A = [list(input()) for _ in range(n)]
f = {'f', 'a', 'c', 'e'}
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = {A[i][j], A[i][j + 1], A[i + 1][j], A[i + 1][j + 1]}
		if s == f:
			cnt += 1
print(cnt)


(n, m) = map(int, input().split())
a = [input().strip() for x in range(n)]
print(sum((set([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]]) == set('face') for i in range(n - 1) for j in range(m - 1))))


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a += [input()]
f = 0
face = 'face'
for i in range(n - 1):
	for j in range(m - 1):
		x = a[i][j:j + 2] + a[i + 1][j:j + 2]
		o = 1
		for k in range(4):
			if not face[k] in x:
				o = 0
				break
		f += o
print(f)


(n, m) = map(int, input().split(' '))
p = [input() for i in range(n)]
r = 0
for i in range(n - 1):
	for j in range(m - 1):
		if {p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1]} == {'f', 'a', 'c', 'e'}:
			r = r + 1
print(r)


def fa(a):
	s = ['f', 'a', 'c', 'e']
	p = 0
	for i in range(len(a)):
		if s.count(a[i]):
			s.remove(a[i])
			p += 1
	if p == 4:
		return 1
	return 0
s = []
k = input().split(' ')
(n, m) = (int(k[0]), int(k[1]))
for i in range(n):
	s += [list(input())]
h = 0
for i in range(n - 1):
	for l in range(m - 1):
		h += fa(s[i][l:l + 2] + s[i + 1][l:l + 2])
print(h)


a = [int(j) for j in input().split()]
w = []
for k in range(a[0]):
	w.append(input())
if a[0] == 1 or a[1] == 1:
	b = 0
else:
	b = 0
	for k in range(a[0] - 1):
		for j in range(a[1] - 1):
			s = w[k][j:j + 2] + w[k + 1][j:j + 2]
			if 'a' in s and 'f' in s and ('c' in s) and ('e' in s):
				b += 1
print(b)


def isface(lst):
	face = set('face')
	for i in range(4):
		if lst[i] in face:
			face.remove(lst[i])
		else:
			return False
	return True
(n, m) = map(int, input().split())
arr = list([input() for i in range(n)])
faces = 0
if not n == 1 and (not m == 1):
	for i in range(n - 1):
		for j in range(m - 1):
			if isface((arr[i][j], arr[i + 1][j], arr[i][j + 1], arr[i + 1][j + 1])):
				faces += 1
print(faces)


nm = input()
n = int(nm.split()[0])
m = int(nm.split()[1])
img = []
faces = 0
for i in range(n):
	x = input()
	img.append(x)
for s in range(len(img)):
	for i in range(len(img[s])):
		loc1 = True
		loc2 = True
		loc3 = True
		loc4 = True
		if i == 0:
			loc1 = False
			loc3 = False
		if s == n - 1:
			loc1 = False
			loc2 = False
		if i == m - 1:
			loc2 = False
			loc4 = False
		if s == 0:
			loc3 = False
			loc4 = False
		if img[s][i] == 'f' and loc1:
			if 'a' in (img[s][i - 1], img[s + 1][i], img[s + 1][i - 1]) and 'c' in (img[s][i - 1], img[s + 1][i], img[s + 1][i - 1]) and ('e' in (img[s][i - 1], img[s + 1][i], img[s + 1][i - 1])):
				faces += 1
		if img[s][i] == 'f' and loc2:
			if 'a' in (img[s][i + 1], img[s + 1][i], img[s + 1][i + 1]) and 'c' in (img[s][i + 1], img[s + 1][i], img[s + 1][i + 1]) and ('e' in (img[s][i + 1], img[s + 1][i], img[s + 1][i + 1])):
				faces += 1
		if img[s][i] == 'f' and loc3:
			if 'a' in (img[s][i - 1], img[s - 1][i], img[s - 1][i - 1]) and 'c' in (img[s][i - 1], img[s - 1][i], img[s - 1][i - 1]) and ('e' in (img[s][i - 1], img[s - 1][i], img[s - 1][i - 1])):
				faces += 1
		if img[s][i] == 'f' and loc4:
			if 'a' in (img[s][i + 1], img[s - 1][i], img[s - 1][i + 1]) and 'c' in (img[s][i + 1], img[s - 1][i], img[s - 1][i + 1]) and ('e' in (img[s][i + 1], img[s - 1][i], img[s - 1][i + 1])):
				faces += 1
print(faces)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(input())
	ans = 0
	for i in range(n - 1):
		for j in range(m - 1):
			B = []
			B.append(A[i][j])
			B.append(A[i][j + 1])
			B.append(A[i + 1][j])
			B.append(A[i + 1][j + 1])
			if sorted(B) == sorted(list('face')):
				ans += 1
	print(ans)
main()


(n, m) = input().split()
n = int(n)
m = int(m)
l = []
for i in range(n):
	l1 = input()
	l.append(l1)
r = 0
for i in range(n - 1):
	for j in range(m - 1):
		k = l[i][j] + l[i][j + 1] + l[i + 1][j] + l[i + 1][j + 1]
		if k.count('f') == 1 and k.count('a') == 1 and (k.count('c') == 1) and (k.count('e') == 1):
			r += 1
print(r)


(n, m) = map(int, input().split())
c = [input() for _ in range(n)]
counter = 0
for i in range(n - 1):
	for j in range(m - 1):
		f = [c[i][j], c[i + 1][j], c[i][j + 1], c[i + 1][j + 1]]
		if 'f' in f and 'a' in f and ('c' in f) and ('e' in f):
			counter += 1
print(counter)


__author__ = 'liraim'

def read():
	input_data = input().split()
	[height, width] = [int(input_data[0]), int(input_data[1])]
	data = []
	for i in range(height):
		data.append(input())
	return (width, height, data)

def solve(task_data):
	(width, height, input_data) = task_data
	count = 0
	for i in range(height - 1):
		for j in range(width - 1):
			line = input_data[i][j] + input_data[i + 1][j] + input_data[i][j + 1] + input_data[i + 1][j + 1]
			if 'f' in line and 'a' in line and ('c' in line) and ('e' in line):
				count += 1
	return count
print(solve(read()))


from sys import stdin
(n, m) = map(int, stdin.readline().split())
a = []
for i in range(0, n):
	a.append(stdin.readline())
res = 0
for i in range(0, n - 1):
	for j in range(0, m - 1):
		r = [a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1]]
		if 'f' not in r:
			continue
		if 'a' not in r:
			continue
		if 'c' not in r:
			continue
		if 'e' not in r:
			continue
		res += 1
print(res)


import string

def main_funtion():
	photo = [list(input()) for i in range([int(i) for i in input().split(' ')][0])]
	counter = 0
	d = {}
	for i in range(len(photo)):
		for j in range(len(photo[i])):
			if (photo[i][j] != 'f' or photo[i][j] != 'a' or photo[i][j] != 'c' or (photo[i][j] != 'e')) and i < len(photo) - 1 and (j < len(photo[i]) - 1) and (set([photo[i][j], photo[i + 1][j], photo[i][j + 1], photo[i + 1][j + 1]]) == set(['f', 'a', 'c', 'e'])):
				counter += 1
	return counter
print(main_funtion())


(a, b) = map(int, input().split())
cases = a
face = set('face')
matrix = []
while cases:
	cases -= 1
	s = list(input())
	matrix.append(s)
check = set()
ans = 0
for row in range(len(matrix)):
	for col in range(len(matrix[0])):
		if matrix[row][col] in face:
			if row < len(matrix) - 1 and col < len(matrix[0]) - 1:
				check.add(matrix[row][col])
				check.add(matrix[row][col + 1])
				check.add(matrix[row + 1][col])
				check.add(matrix[row + 1][col + 1])
				if check == face:
					ans += 1
				check = set()
print(ans)


(n, m) = map(int, input().split())
l = []
s = {'f', 'a', 'c', 'e'}
for i in range(n):
	l.append(input())
c = 0
for i in range(n - 1):
	for j in range(m - 1):
		if set([l[i][j], l[i][j + 1], l[i + 1][j], l[i + 1][j + 1]]) == s:
			c = c + 1
print(c)


(n, m) = [int(i) for i in input().split()]
img = [list(input()) for i in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		arr = [img[i][j], img[i + 1][j], img[i][j + 1], img[i + 1][j + 1]]
		if 'f' in arr and 'a' in arr and ('c' in arr) and ('e' in arr):
			cnt += 1
print(cnt)


(n, m) = [int(x) for x in input().split()]
image = []
for _ in range(n):
	image.append(input())
count = 0
faces = set(['f', 'a', 'c', 'e'])
for i in range(n - 1):
	for j in range(m - 1):
		neighbors = set([image[i][j], image[i][j + 1], image[i + 1][j], image[i + 1][j + 1]])
		if neighbors == faces:
			count += 1
print(count)


(h, w) = map(int, input().split())
a = []
for i in range(h):
	a.append(input())
c = 0
for i in range(h - 1):
	for j in range(w - 1):
		s = a[i][j:j + 2] + a[i + 1][j:j + 2]
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			c += 1
print(c)


(n, m) = list(map(int, input().split()))
board = [input() for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = [board[i][j], board[i + 1][j], board[i][j + 1], board[i + 1][j + 1]]
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			ans += 1
print(ans)


face = set('face')
(n, m) = list(map(int, input().split()))
faces = []
for i in range(n):
	faces.append(list(input()))
count = 0
for i in range(n):
	for j in range(m):
		dxdy = [(0, 0), (0, 1), (1, 1), (1, 0)]
		f = []
		for (dx, dy) in dxdy:
			if 0 <= dy + i < n and 0 <= dx + j < m:
				f.append(faces[i + dy][j + dx])
		if face == set(f):
			count += 1
print(count)


(n, m) = map(int, input().split())
lines = [input() for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		a = lines[i][j] + lines[i + 1][j] + lines[i][j + 1] + lines[i + 1][j + 1]
		if 'f' in a and 'a' in a and ('c' in a) and ('e' in a):
			ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
icon = [input() for i in range(n)]
faces = 0
for i in range(n - 1):
	for j in range(m - 1):
		temp = 0
		temp2 = 0
		temp3 = 0
		temp4 = 0
		if icon[i][j] == 'f':
			temp += 1
		elif icon[i][j] == 'a':
			temp2 += 1
		elif icon[i][j] == 'c':
			temp3 += 1
		elif icon[i][j] == 'e':
			temp4 += 1
		if icon[i + 1][j] == 'f':
			temp += 1
		elif icon[i + 1][j] == 'a':
			temp2 += 1
		elif icon[i + 1][j] == 'c':
			temp3 += 1
		elif icon[i + 1][j] == 'e':
			temp4 += 1
		if icon[i][j + 1] == 'f':
			temp += 1
		elif icon[i][j + 1] == 'a':
			temp2 += 1
		elif icon[i][j + 1] == 'c':
			temp3 += 1
		elif icon[i][j + 1] == 'e':
			temp4 += 1
		if icon[i + 1][j + 1] == 'f':
			temp += 1
		elif icon[i + 1][j + 1] == 'a':
			temp2 += 1
		elif icon[i + 1][j + 1] == 'c':
			temp3 += 1
		elif icon[i + 1][j + 1] == 'e':
			temp4 += 1
		if temp == 1 and temp2 == 1 and (temp3 == 1) and (temp4 == 1):
			faces += 1
print(faces)


import copy
(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = []
for i in range(n):
	s.append(input())
if n < 2 or m < 2:
	print(0)
else:
	count = 0
	a = ['f', 'a', 'c', 'e']
	for i in range(n - 1):
		for j in range(m - 1):
			b = copy.deepcopy(a)
			if s[i][j] in b:
				b.remove(s[i][j])
				if s[i + 1][j] in b:
					b.remove(s[i + 1][j])
					if s[i][j + 1] in b:
						b.remove(s[i][j + 1])
						if s[i + 1][j + 1] in b:
							b.remove(s[i + 1][j + 1])
							count += 1
	print(count)


(n, m) = map(int, input().split())
a = []
c = 0
for i in range(n):
	s = list(input())
	a.append(s)
for i in range(m - 1):
	for j in range(n - 1):
		s = a[j][i] + a[j + 1][i] + a[j][i + 1] + a[j + 1][i + 1]
		s = sorted(s)
		s = ''.join(s)
		if s == 'acef':
			c += 1
print(c)


(n, m) = map(int, input().split())
p = []
for i in range(n):
	a = list(input())
	p.append(a)
col = 0
for i in range(n - 1):
	for t in range(m - 1):
		k = set()
		k.add(p[i][t])
		k.add(p[i + 1][t])
		k.add(p[i][t + 1])
		k.add(p[i + 1][t + 1])
		if 'f' in k and 'a' in k and ('c' in k) and ('e' in k):
			col += 1
print(col)


R = lambda : list(map(int, input().split()))
(n, m) = R()
rs = 0
a = []
for i in range(n):
	a.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		c = []
		c.append(a[i][j])
		c.append(a[i + 1][j])
		c.append(a[i][j + 1])
		c.append(a[i + 1][j + 1])
		u = set(c)
		if len(u) == 4:
			if 'f' in u:
				if 'a' in u:
					if 'c' in u:
						if 'e' in u:
							rs += 1
print(rs)


(n, m) = map(int, input().split())
t = []
cnt = 0
for i in range(n):
	t.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		s = ''
		s += t[i][j]
		s += t[i + 1][j]
		s += t[i][j + 1]
		s += t[i + 1][j + 1]
		s = ''.join(sorted(list(s)))
		if s == 'acef':
			cnt += 1
print(cnt)


(n, m) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append(input())
res = 0
z = ['face', 'faec', 'feac', 'feca', 'fcae', 'fcea', 'eafc', 'eacf', 'ecaf', 'ecfa', 'efac', 'efca', 'acfe', 'acef', 'aecf', 'aefc', 'afce', 'afec', 'cafe', 'caef', 'ceaf', 'cefa', 'cfea', 'cfae']
for i in range(1, n):
	for j in range(1, m):
		if a[i][j] + a[i][j - 1] + a[i - 1][j] + a[i - 1][j - 1] in z:
			res += 1
print(res)


nub = input().split(' ')
n = int(nub[0])
m = int(nub[1])
matrix = []
for i in range(n):
	matrix.append(input())

def face(matx, i, j):
	if matx[i][j] == 'f' or matx[i + 1][j] == 'f' or matx[i][j + 1] == 'f' or (matx[i + 1][j + 1] == 'f'):
		if matx[i][j] == 'a' or matx[i + 1][j] == 'a' or matx[i][j + 1] == 'a' or (matx[i + 1][j + 1] == 'a'):
			if matx[i][j] == 'c' or matx[i + 1][j] == 'c' or matx[i][j + 1] == 'c' or (matx[i + 1][j + 1] == 'c'):
				if matx[i][j] == 'e' or matx[i + 1][j] == 'e' or matx[i][j + 1] == 'e' or (matx[i + 1][j + 1] == 'e'):
					return 1
	return 0
k = 0
for i in range(n - 1):
	for j in range(m - 1):
		if face(matrix, i, j) == 1:
			k += 1
print(k)


(n, m) = map(int, input().split())
c = []
for i in range(n):
	c.append(input())
z = 0
for i in range(len(c) - 1):
	for j in range(len(c[i]) - 1):
		l = []
		l.append(c[i][j])
		l.append(c[i + 1][j])
		l.append(c[i][j + 1])
		l.append(c[i + 1][j + 1])
		if l.count('f') == 1 and l.count('a') == 1 and (l.count('c') == 1) and (l.count('e') == 1):
			z += 1
print(z)


a = input().split()
per = input()
answer = 0
for j in range(int(a[0]) - 1):
	per1 = input()
	for i in range(int(a[1]) - 1):
		A = set()
		A.add(per[i + 1])
		A.add(per[i])
		A.add(per1[i])
		A.add(per1[i + 1])
		if 'f' in A and 'a' in A and ('c' in A) and ('e' in A):
			answer += 1
	per = per1
print(answer)


t = ['f', 'a', 'c', 'e']
t.sort()
(n, m) = map(int, input().split())
f = []
for j in range(n):
	f.append(list(input()))
if n == 1 or m == 1:
	print(0)
else:
	p = 0
	for i in range(n - 1):
		h = []
		for j in range(m - 1):
			h.append(f[i][j])
			h.append(f[i][j + 1])
			h.append(f[i + 1][j])
			h.append(f[i + 1][j + 1])
			h.sort()
			if h == t:
				p += 1
			h = []
	print(p)


mat = []
cnt = 0
from collections import Counter
(n, m) = map(int, input().split())
for i in range(n):
	mat.append(list(input()))
for i in range(1, n):
	for j in range(1, m):
		s = mat[i][j] + mat[i][j - 1] + mat[i - 1][j] + mat[i - 1][j - 1]
		if Counter(s) == Counter('face'):
			cnt += 1
print(cnt)


(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(list(input()))
F = []
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		if A[i][j] != 'x':
			F = [A[i][j], A[i][j + 1], A[i + 1][j], A[i + 1][j + 1]]
			if 'f' in F and 'a' in F and ('c' in F) and ('e' in F):
				count += 1
print(count)


(n, m) = list(map(int, input().split()))
board = []
for i in range(n):
	board.append(input())
ok_set = set(['f', 'a', 'c', 'e'])
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		cur_set = set([board[i][j], board[i][j + 1], board[i + 1][j], board[i + 1][j + 1]])
		if cur_set == ok_set:
			ans += 1
print(ans)


(l, b) = map(int, input().split())
t = [input() for i in range(l)]
count = 0
if l < 2 or b < 2:
	print(0)
else:
	j = 0
	i = 0
	for i in range(l - 1):
		for j in range(b - 1):
			A = t[i][j]
			B = t[i][j + 1]
			C = t[i + 1][j]
			D = t[i + 1][j + 1]
			l = [A, B, C, D]
			if l.count('f') == 1 and l.count('a') == 1 and (l.count('c') == 1) and (l.count('e') == 1):
				count += 1
	print(count)


import sys

def main():
	fin = sys.stdin
	(n, m) = map(int, fin.readline().split())
	A = []
	for i in range(n):
		A.append(fin.readline().rstrip())
	cnt = 0
	for i in range(n - 1):
		for j in range(m - 1):
			S = {A[i][j], A[i][j + 1], A[i + 1][j], A[i + 1][j + 1]}
			if 'f' in S and 'a' in S and ('c' in S) and ('e' in S):
				cnt += 1
	print(cnt)
	fin.close()
main()


(m, n) = [int(i) for i in input().split()]
image = []
for i in range(m):
	image.append(' '.join(input()).split())

def is_face(square):
	face = ['f', 'a', 'c', 'e']
	char_count = 0
	for i in range(2):
		for j in range(2):
			if square[i][j] in face:
				char_count += 1
				face.remove(square[i][j])
	if char_count > 1:
		if not face:
			return 2
		else:
			return 1
	else:
		return 0

def face_dection(m, n, image):
	if n < 2 or m < 2:
		return 0
	(col, row) = (0, 0)
	face_count = 0
	while row != m - 1:
		square = [image[row][col:col + 2], image[row + 1][col:col + 2]]
		offset = 1
		face = is_face(square)
		if face == 2:
			face_count += 1
		elif not face:
			offset = 2
		if col + offset > n - 2:
			col = 0
			row += 1
		else:
			col += offset
	return face_count
print(face_dection(m, n, image))


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if ''.join(sorted((a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]))) == 'acef':
			ans += 1
print(ans)


nub = input().split(' ')
n = int(nub[0])
m = int(nub[1])
matrix = []
for i in range(n):
	matrix.append(input())

def face(matx, i, j):
	if ''.join(sorted(matx[i][j:j + 2] + matx[i + 1][j:j + 2])) == 'acef':
		return 1
	return 0
k = 0
for i in range(n - 1):
	for j in range(m - 1):
		if face(matrix, i, j) == 1:
			k += 1
print(k)


def inp():
	(n, m) = map(int, input().split())
	table = []
	for i in range(n):
		table.append(input())
	return (n, m, table)

def check(letters):
	return sorted(list(letters)) == ['a', 'c', 'e', 'f']

def main():
	(n, m, t) = inp()
	k = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if check(t[i][j:j + 2] + t[i + 1][j:j + 2]):
				k += 1
	print(k)
main()


(n, m) = [int(i) for i in input().split()]
a = [0] * n
for i in range(n):
	a[i] = input().split()[0]
ctr = 0
for i in range(n - 1):
	for j in range(m - 1):
		if set([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]]) == {'f', 'a', 'c', 'e'}:
			ctr += 1
print(ctr)


q = [int(i) for i in input().split()]
n = q[0]
m = q[1]
a = []
face = set('face')
count = 0
for inp in range(n):
	a.append(input())
if n < 2 or m < 2:
	print(0)
else:
	for i in range(n - 1):
		for j in range(m - 1):
			string = a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i + 1][j + 1]
			if set(string) == face:
				count += 1
	print(count)


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		string = ''
		string += arr[i][j]
		string += arr[i + 1][j]
		string += arr[i][j + 1]
		string += arr[i + 1][j + 1]
		if 'f' in string and 'a' in string and ('c' in string) and ('e' in string):
			ans += 1
print(ans)


def is_face(sub_img):
	for c in 'face':
		if not c in sub_img:
			return False
	return True

class CodeforcesTask549ASolution:

	def __init__(self):
		self.result = ''
		self.dims = [0, 0]
		self.image = []

	def read_input(self):
		self.dims = [int(x) for x in input().split(' ')]
		for x in range(self.dims[0]):
			self.image.append(input())

	def process_task(self):
		faces = 0
		for x in range(self.dims[1] - 1):
			for y in range(self.dims[0] - 1):
				substr = self.image[y][x:x + 2] + self.image[y + 1][x:x + 2]
				if is_face(substr):
					faces += 1
		self.result = str(faces)

	def get_result(self):
		return self.result
Solution = CodeforcesTask549ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
a = list()
x = 0
for i in range(n):
	a.append(input())
for i in range(n):
	for j in range(m):
		b = list()
		try:
			b.append(a[i][j])
			b.append(a[i][j + 1])
			b.append(a[i + 1][j])
			b.append(a[i + 1][j + 1])
			if 'f' in b and 'a' in b and ('c' in b) and ('e' in b):
				x += 1
		except:
			pass
print(x)


(n, m) = [int(x) for x in input().strip().split()]
image = [input() for i in range(n)]
res = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = image[i][j] + image[i][j + 1] + image[i + 1][j] + image[i + 1][j + 1]
		if ''.join(sorted(s)) == 'acef':
			res += 1
print(res)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
a = 0
for i in range(n - 1):
	for r in range(m - 1):
		t = l[i][r:r + 2] + l[i + 1][r:r + 2]
		if 'f' in t and 'a' in t and ('c' in t) and ('e' in t):
			a += 1
print(a)


(n, m) = [int(x) for x in input().split()]
a = []
letters = ['f', 'a', 'c', 'e']
count = 0
if m < 2 or n < 2:
	print(count)
else:
	for i in range(n):
		a.append(input())
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] != 'x':
				if a[i][j + 1] != 'x' and a[i + 1][j] != 'x' and (a[i + 1][j + 1] != 'x'):
					if a[i][j] != a[i][j + 1] and a[i][j] != a[i + 1][j + 1] and (a[i][j] != a[i + 1][j]) and (a[i + 1][j] != a[i][j + 1]) and (a[i + 1][j] != a[i + 1][j + 1]) and (a[i][j + 1] != a[i + 1][j + 1]):
						if a[i][j] in letters and a[i][j + 1] in letters and (a[i + 1][j] in letters) and (a[i + 1][j + 1] in letters):
							count += 1
	print(count)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline().strip())
(n, m) = get_int_list()
matrix = []
s = {'f', 'a', 'c', 'e'}
count = 0
for i in range(n):
	matrix.append(list(get_string()))
for i in range(n - 1):
	for j in range(m - 1):
		if set([matrix[i][j], matrix[i][j + 1], matrix[i + 1][j], matrix[i + 1][j + 1]]) == s:
			count += 1
print(count)


(n, m) = map(int, input().split())
prev = input()
if n == 1 or m == 1:
	print(0)
else:
	count = 0
	for i in range(n - 1):
		now = input()
		for j in range(m - 1):
			s = prev[j:j + 2] + now[j:j + 2]
			if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
				count += 1
		prev = now
	print(count)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
d = ['f', 'a', 'c', 'e']
ans = 0
for j in range(n - 1):
	for k in range(m - 1):
		if a[j][k] in d and a[j][k + 1] in d and (a[j + 1][k] in d) and (a[j + 1][k + 1] in d) and (len({a[j][k], a[j][k + 1], a[j + 1][k], a[j + 1][k + 1]}) == 4):
			ans += 1
print(ans)


data = []
face = set({'f', 'a', 'c', 'e'})

def check(data, i, j):
	s = set()
	s.add(data[i][j])
	s.add(data[i + 1][j])
	s.add(data[i + 1][j + 1])
	s.add(data[i][j + 1])
	if len(s & face) == 4:
		return True
	return False

def __starting_point():
	(n, m) = map(int, input().split())
	for i in range(n):
		data.append(input())
	total = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if check(data, i, j):
				total += 1
	print(total)
__starting_point()


(a, b) = input().split()
n = int(a)
m = int(b)
t = ['' for j in range(n)]
for i in range(n):
	t[i] = input()
v = 0

def test(a, b, c, d):
	g = [0 for i in range(200)]
	g[ord(a)] += 1
	g[ord(b)] += 1
	g[ord(c)] += 1
	g[ord(d)] += 1
	return g[ord('f')] * g[ord('a')] * g[ord('c')] * g[ord('e')] == 1
for i in range(n - 1):
	for j in range(m - 1):
		if test(t[i][j], t[i + 1][j], t[i][j + 1], t[i + 1][j + 1]):
			v += 1
print(v)


(n, m) = [int(i) for i in input().split()]
l = []
for i in range(n):
	l.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = l[i][j] + l[i][j + 1] + l[i + 1][j] + l[i + 1][j + 1]
		s = str(set(s))
		if s.count('f') + s.count('a') + s.count('c') + s.count('e') == 4:
			ans += 1
print(ans)


(m, n) = [int(i) for i in input().split()]
t = 0
a = []
for i in range(m):
	a.append(input())
for i in range(m - 1):
	for j in range(n - 1):
		b = []
		b.append(a[i][j])
		b.append(a[i + 1][j])
		b.append(a[i][j + 1])
		b.append(a[i + 1][j + 1])
		if 'f' in b and 'a' in b and ('c' in b) and ('e' in b):
			t += 1
print(t)


(n, m) = map(int, input().split())
count = 0
w = [input() for i in range(n)]
for i in range(n - 1):
	for j in range(m - 1):
		if {w[i][j], w[i + 1][j], w[i][j + 1], w[i + 1][j + 1]} == {'f', 'a', 'c', 'e'}:
			count += 1
print(count)


(h, w) = map(int, input().split())
P = []
for i in range(1, h + 1):
	P.append(list(input().strip()))
c = 0
for i in range(h - 1):
	for j in range(w - 1):
		word = P[i][j] + P[i][j + 1] + P[i + 1][j] + P[i + 1][j + 1]
		if ''.join(sorted(word)) == 'acef':
			c += 1
print(c)


(N, M) = list(map(int, input().split()))
Seq = [list(input()) for I in range(N)]
Ans = 0
for I in range(N - 1):
	for J in range(M - 1):
		Det = ['f', 'a', 'c', 'e']
		Used = []
		if Seq[I][J] in Det:
			Used.append(Seq[I][J])
			if Seq[I + 1][J] in Det and (not Seq[I + 1][J] in Used):
				Used.append(Seq[I + 1][J])
				if Seq[I][J + 1] in Det and (not Seq[I][J + 1] in Used):
					Used.append(Seq[I][J + 1])
					if Seq[I + 1][J + 1] in Det and (not Seq[I + 1][J + 1] in Used):
						Ans += 1
print(Ans)


from sys import *
(n, m) = map(int, input().split())
l = [input() for i in range(n)]
ans = 0
if min(n, m) == 1:
	print(ans)
	exit()
for i in range(1, n):
	for j in range(1, m):
		t = [l[i][j], l[i][j - 1], l[i - 1][j], l[i - 1][j - 1]]
		if 'f' in t and 'a' in t and ('c' in t) and ('e' in t):
			ans += 1
print(ans)


R = lambda : map(int, input().split())
(n, m) = R()
a = [[j for j in input()] for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if sorted(a[i][j:j + 2] + a[i + 1][j:j + 2]) == sorted('face'):
			ans += 1
print(ans)


(n, m) = map(int, input().split())
face_li = []
face_new = []
count = 0
for i in range(0, n):
	temp = ''.join(input().split())
	face_li.append(temp)
for i in range(0, n - 1):
	for j in range(0, m - 1):
		temp = face_li[i][j:j + 2]
		temp1 = face_li[i + 1][j:j + 2]
		face_new.append(temp)
		face_new.append(temp1)
		face_new = ''.join(face_new)
		face_new = list(face_new)
		if 'f' in face_new and 'a' in face_new and ('c' in face_new) and ('e' in face_new):
			count += 1
			face_new.clear()
		else:
			face_new.clear()
print(count)


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(input()))
ans = list('acef')
co = 0
for i in range(n - 1):
	for j in range(m - 1):
		li = []
		li.append(l[i][j])
		li.append(l[i + 1][j])
		li.append(l[i][j + 1])
		li.append(l[i + 1][j + 1])
		if sorted(li) == ans:
			co += 1
print(co)


def face(b, i, j):
	p = b[i][j] + b[i][j + 1] + b[i + 1][j] + b[i + 1][j + 1]
	if p.find('f') + p.find('a') + p.find('c') + p.find('e') == 6:
		return 1
	return 0
a = list(map(int, input().split()))
b = []
r = 0
for i in range(a[0]):
	b.append(input())
for i in range(a[0] - 1):
	for j in range(a[1] - 1):
		r += face(b, i, j)
print(r)


(a, b) = map(int, input().split())
l = []
p = 0
for m in range(a):
	lPrime = list(input())
	l.append(lPrime)
for i in range(0, a - 1):
	for j in range(0, b - 1):
		u = l[i][j] + l[i][j + 1] + l[i + 1][j] + l[i + 1][j + 1]
		if 'f' in u and 'a' in u and ('c' in u) and ('e' in u):
			p = p + 1
print(p)


(r, c) = map(lambda x: int(x), input().split())
img = []
for i in range(r):
	img.append([])
	line = input()
	for j in range(c):
		img[i].append(line[j])
count = 0
for i in range(r - 1):
	for j in range(c - 1):
		test = [img[i][j], img[i + 1][j], img[i][j + 1], img[i + 1][j + 1]]
		if all([x in test for x in 'face']):
			count += 1
print(count)


poss = ['face', 'faec', 'fcae', 'fcea', 'feac', 'feca', 'afce', 'afec', 'acfe', 'acef', 'aefc', 'aecf', 'cfae', 'cfea', 'cafe', 'caef', 'cefa', 'ceaf', 'efac', 'efca', 'eafc', 'eacf', 'ecfa', 'ecaf']

def check(p, i, j, k):
	return p[i][j:j + 2] == poss[k][0:2] and p[i + 1][j:j + 2] == poss[k][2:4]
(n, m) = map(int, input().split(' '))
p = [input() for _ in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		for k in range(24):
			if check(p, i, j, k):
				ans += 1
print(ans)


(n, m) = map(int, input().split())
if n == 1 or m == 1:
	print(0)
	exit()
arr = []
check = set(['f', 'a', 'c', 'e'])
for i in range(n):
	arr.append(input())
cnt = 0
for i in range(n):
	for j in range(m):
		temp = set()
		temp.add(arr[i][j])
		if i + 1 < n:
			temp.add(arr[i + 1][j])
		if j + 1 < m:
			temp.add(arr[i][j + 1])
		if i + 1 < n and j + 1 < m:
			temp.add(arr[i + 1][j + 1])
		if temp == check:
			cnt = cnt + 1
print(cnt)


def tu():
	(n, m) = map(int, input().split())
	a = 'x' * (m + 1)
	p = ['f', 'a', 'c', 'e']
	d = dict()
	ans = 0
	for i in range(97, 123):
		d[chr(i)] = 0
	for i in range(n):
		s = input() + 'x'
		for j in range(m):
			d[s[j]] = 1
			d[s[j + 1]] = 1
			d[a[j]] = 1
			d[a[j + 1]] = 1
			for j in p:
				if d[j] == 0:
					break
			else:
				ans += 1
			for j in p:
				d[j] = 0
		a = s
	print(ans)
tu()


words = ['face', 'faec', 'feac', 'feca', 'fcea', 'fcae']
letters = 'aec'
for i in range(3):
	for j in range(6):
		word = words[j][1:]
		word = word.replace(letters[i], 'f')
		word = letters[i] + word
		words.append(word)
(h, w) = map(int, input().split())
P = []
for i in range(1, h + 1):
	P.append(list(input().strip()))
c = 0
for i in range(h - 1):
	for j in range(w - 1):
		word = P[i][j] + P[i][j + 1] + P[i + 1][j] + P[i + 1][j + 1]
		if word in words:
			c += 1
print(c)


tmp = input().split()
tmp[0] = int(tmp[0])
tmp[1] = int(tmp[1])
face = 'acef'
my_str = []
for i in range(0, tmp[0]):
	my_str.append(input())
count = 0
for i in range(0, tmp[0] - 1):
	for j in range(0, tmp[1] - 1):
		my = ''
		my += my_str[i][j]
		my += my_str[i][j + 1]
		my += my_str[i + 1][j]
		my += my_str[i + 1][j + 1]
		my = list(my)
		my.sort()
		my = ''.join(my)
		if my == face:
			count += 1
print(count)


def calc(img):
	nr = len(img)
	nc = len(img[0])
	ret = 0
	for i in range(nr - 1):
		for j in range(nc - 1):
			tset = set()
			tset.add(img[i][j])
			tset.add(img[i][j + 1])
			tset.add(img[i + 1][j])
			tset.add(img[i + 1][j + 1])
			if 'f' in tset and 'a' in tset and ('c' in tset) and ('e' in tset):
				ret += 1
	return ret

def main():
	items = input().split()
	nr = int(items[0])
	nc = int(items[1])
	img = []
	for _ in range(nr):
		img.append(input())
	print(calc(img))
main()


(n, m) = map(int, input().split())
table = []
for i in range(n):
	table.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		di = [0, 0, 1, 1]
		dj = [0, 1, 0, 1]
		d = {}
		for k in range(4):
			c = table[i + di[k]][j + dj[k]]
			d[c] = d.get(c, 0) + 1
		flg = True
		for c in 'face':
			if c not in d or d[c] != 1:
				flg = False
		if flg:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
image = []
for _ in range(n):
	image.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if set([image[i][j], image[i][j + 1], image[i + 1][j], image[i + 1][j + 1]]) == set('face'):
			ans += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
d = [input() for i in range(n)]
result = 0
for i in range(n - 1):
	for j in range(m - 1):
		if sorted(d[i][j] + d[i + 1][j] + d[i][j + 1] + d[i + 1][j + 1]) == sorted(list('face')):
			result += 1
print(result)


(n, m) = [int(c) for c in input().split()]
lines = []
for i in range(n):
	lines.append(input())
f = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = set()
		s.add(lines[i][j])
		s.add(lines[i + 1][j])
		s.add(lines[i][j + 1])
		s.add(lines[i + 1][j + 1])
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			f += 1
print(f)


def main():
	(n, m) = map(int, input().split())
	(hi, res) = ([0], 0)
	face = dict.fromkeys('abcdefghijklmnopqrstuvwxyz', 0)
	face.update({'f': 1, 'a': 2, 'c': 4, 'e': 8})
	for _ in range(n):
		lo = [face[c] for c in input()]
		res += sum((f + a + c + e == 15 for (f, a, c, e) in zip(hi, hi[1:], lo, lo[1:])))
		hi = lo
	print(res)
main()


vars = ['face', 'faec', 'feac', 'feca', 'fcae', 'fcea', 'eafc', 'eacf', 'ecaf', 'ecfa', 'efac', 'efca', 'acfe', 'acef', 'aecf', 'aefc', 'afce', 'afec', 'cafe', 'caef', 'ceaf', 'cefa', 'cfea', 'cfae']

def define_faces(n, m, lst):
	count = 0
	for i in range(n):
		for j in range(m):
			if i + 1 < n and j + 1 < m and (lst[i + 1][j + 1] + lst[i + 1][j] + lst[i][j + 1] + lst[i][j] in vars):
				count += 1
	return count
(n1, m1) = [int(i) for i in input().split()]
b = list()
for z in range(n1):
	s = input()
	b.append(list(s))
print(define_faces(n1, m1, b))


(n, m) = [int(i) for i in input().split()]
matrix = []
for i in range(n):
	matrix.append(input())
ex = ['f', 'a', 'c', 'e']
ex = sorted(ex)
container = []
if n < 2 or m < 2:
	print(0)
else:
	ans = 0
	for i in range(n - 1):
		for j in range(m - 1):
			container.append(matrix[i][j])
			container.append(matrix[i][j + 1])
			container.append(matrix[i + 1][j])
			container.append(matrix[i + 1][j + 1])
			container = sorted(container)
			if container == ex:
				ans += 1
			container = []
	print(ans)


(n, m) = map(int, input().split())
M = [str(input()) for _ in range(n)]
r = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = set()
		s.add(M[i][j])
		s.add(M[i + 1][j])
		s.add(M[i][j + 1])
		s.add(M[i + 1][j + 1])
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			r += 1
print(r)


(n, m) = list(map(int, input().split(' ')))
a = []
str = ''
count = 0
for i in range(n):
	a.append(input())
for i in range(n - 1):
	for j in range(m):
		str = a[i][j:j + 2] + a[i + 1][j:j + 2]
		if sorted(str) == [*'acef']:
			count += 1
		str = ''
print(count)


(n, m) = map(int, input().split())
letters = list((input() for i in range(n)))
match_word = sorted('face')
faces = 0
for i in range(n - 1):
	for j in range(m - 1):
		faces += sorted(letters[i][j:j + 2] + letters[i + 1][j:j + 2]) == match_word
print(faces)


(n, m) = map(int, input().split())
t = [input() for i in range(n)]
print(sum((sorted(t[i][j:j + 2] + t[i + 1][j:j + 2]) == sorted('face') for i in range(n - 1) for j in range(m - 1))))


(n, m) = map(int, input().split())
x = []
for i in range(n):
	x.append(list(input()))
if n == 1 or m == 1:
	print(0)
	exit()
z = []
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		z.append(x[i][j])
		z.append(x[i][j + 1])
		z.append(x[i + 1][j])
		z.append(x[i + 1][j + 1])
		z.sort()
		Z = ''.join(z)
		if Z == 'acef':
			ans += 1
		z = []
print(ans)


(n, m) = [int(i) for i in input().split()]
lines = []
res = 0
for i in range(n):
	lines.append(input().strip())
for x in range(n - 1):
	for y in range(m - 1):
		line = lines[x][y] + lines[x + 1][y] + lines[x][y + 1] + lines[x + 1][y + 1]
		if 'f' in line and 'a' in line and ('c' in line) and ('e' in line):
			res += 1
print(res)


import sys
import math
(n, m) = map(int, input().split())
b = []
for i in range(n):
	b.append(input())
(f, a, c, e) = (False, False, False, False)
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		for o in range(i, i + 2):
			for p in range(j, j + 2):
				if b[o][p] == 'f':
					f = True
				if b[o][p] == 'a':
					a = True
				if b[o][p] == 'c':
					c = True
				if b[o][p] == 'e':
					e = True
		if f == c == a == e == True:
			ans += 1
		(f, a, c, e) = (False, False, False, False)
print(ans)


numbers = [int(n) for n in input().split()]
a = numbers[0]
b = numbers[1]
text = []
face = 'face'
tmp = ''
count = 0
text = [input() for i in range(a)]
for i in range(a - 1):
	for j in range(b - 1):
		if text[i][j] in face:
			tmp += text[i][j] + text[i + 1][j] + text[i][j + 1] + text[i + 1][j + 1]
			if 'f' in tmp and 'a' in tmp and ('c' in tmp) and ('e' in tmp):
				count += 1
			tmp = ''
print(count)


import sys
Input = lambda : map(int, sys.stdin.readline().split())
res = 0
(n, m) = Input()
Pic = list()
for i in range(n):
	Pic.append(input())
Face = 'acef'
for i in range(n):
	for j in range(m):
		if Pic[i][j] in Face:
			try:
				if ''.join(sorted(Pic[i][j] + Pic[i][j + 1] + Pic[i + 1][j] + Pic[i + 1][j + 1])) == Face:
					res += 1
			except:
				pass
sys.stdout.write(str(res) + '\n')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
ans = 0
if n >= 2:
	for i in range(n):
		for j in range(m):
			if i < n - 1 and j < m - 1:
				if set(a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1]) == {'c', 'a', 'e', 'f'}:
					ans += 1
	print(ans)
else:
	print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in [0] * n]
r = 0
for i in range(n - 1):
	for j in range(m - 1):
		r += {*a[i][j:j + 2], *a[i + 1][j:j + 2]} == {*'face'}
print(r)


import sys
(n, m) = map(int, sys.stdin.readline().split())
ans = 0
line1 = input().strip()
for _ in range(n - 1):
	line2 = input().strip()
	for i in range(m - 1):
		if {line1[i], line1[i + 1], line2[i], line2[i + 1]} == {'f', 'a', 'c', 'e'}:
			ans += 1
	line1 = line2
print(ans)


(n, m) = map(int, input().split())
s = list()
a = ['f', 'a', 'c', 'e']
result = 0
for i in range(n):
	s.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		if s[i][j] in a:
			a.remove(s[i][j])
			if s[i][j + 1] in a:
				a.remove(s[i][j + 1])
				if s[i + 1][j] in a:
					a.remove(s[i + 1][j])
					if s[i + 1][j + 1] in a:
						result += 1
						a = ['f', 'a', 'c', 'e']
					else:
						a = ['f', 'a', 'c', 'e']
				else:
					a = ['f', 'a', 'c', 'e']
			else:
				a = ['f', 'a', 'c', 'e']
		else:
			a = ['f', 'a', 'c', 'e']
print(result)


(n, m) = input().split()
(n, m) = (int(n), int(m))
l = []
count = 0
for i in range(n):
	l.append(list(input()))
for i in range(n - 1):
	for j in range(m - 1):
		p = []
		p.append(l[i + 0][j + 0])
		p.append(l[i + 0][j + 1])
		p.append(l[i + 1][j + 1])
		p.append(l[i + 1][j + 0])
		if 'f' in p and 'a' in p and ('c' in p) and ('e' in p):
			count += 1
print(count)


(n, m) = map(int, input().split())
alist = []
for i in range(n):
	word = str(input())
	blist = []
	for i in range(len(word)):
		blist.append(word[i])
	alist.append(blist)
count = 0
if m == 1 or n == 1:
	print('0')
else:
	for i in range(1, n):
		for j in range(1, m):
			clist = []
			clist.append(alist[i - 1][j - 1])
			clist.append(alist[i][j])
			clist.append(alist[i][j - 1])
			clist.append(alist[i - 1][j])
			if 'f' in clist and 'a' in clist and ('c' in clist) and ('e' in clist):
				count = count + 1
			else:
				continue
	print(count)


(n, m) = [int(i) for i in input().split()]
image = []
res = 0
for i in range(n):
	line = input()
	image.append(line)
lvl = 0
res_list = []
while lvl < n - 1:
	pos1 = 0
	while pos1 < len(line) - 1:
		str1 = image[lvl][pos1] + image[lvl][pos1 + 1]
		str2 = image[lvl + 1][pos1] + image[lvl + 1][pos1 + 1]
		str3 = str1 + str2
		scan = [i for i in str3]
		res_list.append(scan)
		pos1 += 1
	lvl += 1
for square in res_list:
	if 'f' in square:
		if 'a' in square:
			if 'c' in square:
				if 'e' in square:
					res += 1
print(res)


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
(n, k) = multi()
a = []
for i in range(n):
	a.append(list(str(input())))
temp = []
ans = 0
for i in range(n - 1):
	for j in range(k - 1):
		temp = [a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]]
		if temp.count('f') == 1 and temp.count('a') == 1 and (temp.count('c') == 1) and (temp.count('e') == 1):
			ans += 1
print(ans)


(n, m) = map(int, input().split())
a = list()
for i in range(n):
	a.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		z = set([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]])
		if z == set('face'):
			ans += 1
print(ans)


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(input())
face = ['f', 'a', 'c', 'e']
face.sort()
aux = []
res = 0
for i in range(n - 1):
	for j in range(m - 1):
		if matrix[i][j] != 'x':
			aux.append(matrix[i][j])
			aux.append(matrix[i][j + 1])
			aux.append(matrix[i + 1][j])
			aux.append(matrix[i + 1][j + 1])
			aux.sort()
		if face == aux:
			res += 1
		aux.clear()
print(res)


a = []

def check(i, j):
	global a
	x = [a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]]
	x.sort()
	if x == ['a', 'c', 'e', 'f']:
		return 1
	return 0
(n, m) = map(int, input().split())
for i in range(n):
	a.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		ans += check(i, j)
print(ans)


def main():
	(n, m) = read()
	s = []
	for i in range(n):
		s.append(read(0))
	ans = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if {s[i][j], s[i][j + 1], s[i + 1][j], s[i + 1][j + 1]} == set('face'):
				ans += 1
	return ans

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


def f(c):
	if c == 'f':
		return 1
	elif c == 'a':
		return 10
	elif c == 'c':
		return 100
	elif c == 'e':
		return 1000
	return 0
(n, m) = [int(j) for j in input().split()]
mat = []
for j in range(n):
	mat.append(list(str(input())))
count = 0
for j in range(n - 1):
	for k in range(m - 1):
		c = f(mat[j][k]) + f(mat[j][k + 1]) + f(mat[j + 1][k]) + f(mat[j + 1][k + 1])
		if c == 1111:
			count += 1
print(count)


(n, m) = map(int, input().split())
g = [list(input()) for _ in range(n)]
r = 0
for i in range(n - 1):
	for j in range(m - 1):
		if set([g[i][j], g[i + 1][j + 1], g[i][j + 1], g[i + 1][j]]) == set('face'):
			r += 1
print(r)


(n, m) = (int(x) for x in input().split())
a = []
for i in range(n):
	a.append(input())
ok = set('face')
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		test = set([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]])
		if test == ok:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
a = [input().replace('', ' ').split() for i in range(n)]
res = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = a[i][j] + a[i][j + 1] + a[i + 1][j] + a[i + 1][j + 1]
		if sorted(s) == ['a', 'c', 'e', 'f']:
			res += 1
print(res)


(n, m) = map(int, input().split())
a = [[0] * m for i in range(n)]
for i in range(n):
	tmp = input()
	for j in range(len(tmp)):
		a[i][j] = tmp[j]
set_ = set()
s = 0
e = 0
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 'a' or a[i][j] == 'f' or a[i][j] == 'e' or (a[i][j] == 'c'):
			set_.add(a[i][j])
			s = s + 1
		if j + 1 < m:
			if a[i][j + 1] == 'e' or a[i][j + 1] == 'a' or a[i][j + 1] == 'c' or (a[i][j + 1] == 'f'):
				if a[i][j + 1] not in set_:
					s = s + 1
					set_.add(a[i][j + 1])
		if i + 1 < n and j + 1 < m:
			if a[i + 1][j + 1] == 'e' or (a[i + 1][j + 1] == 'c' or a[i + 1][j + 1] == 'f' or a[i + 1][j + 1] == 'a'):
				if a[i + 1][j + 1] not in set_:
					s = s + 1
					set_.add(a[i + 1][j + 1])
		if i + 1 < n:
			if a[i + 1][j] == 'a' or a[i + 1][j] == 'e' or a[i + 1][j] == 'c' or (a[i + 1][j] == 'f'):
				if a[i + 1][j] not in set_:
					s = s + 1
					set_.add(a[i + 1][j])
		if s == 4:
			e = e + 1
		s = 0
		set_ = set()
print(e)


__author__ = 'Adam'
import sys
(n, m) = sys.stdin.readline().split(' ')
(n, m) = (int(n), int(m))
data = []
for i in range(n):
	data.append(sys.stdin.readline()[:m])
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		right = [data[i][j], data[i][j + 1], data[i + 1][j], data[i + 1][j + 1]]
		if set(right) == set(['f', 'a', 'c', 'e']):
			count += 1
print(count)


(n, m) = map(int, input().split())
s = []
k = 0
face = ['f', 'a', 'c', 'e']
face.sort()
for i in range(n):
	s.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		isface = []
		isface.append(s[i][j])
		isface.append(s[i][j + 1])
		isface.append(s[i + 1][j])
		isface.append(s[i + 1][j + 1])
		isface.sort()
		if isface == face:
			k += 1
print(k)


import sys
(rows, cols) = map(int, input().split())
matrix = []
counter = 0
if rows == 1 or cols == 1:
	print(0)
	sys.exit()
for i in range(0, rows):
	lst = list(str(input()))
	matrix.append(lst)
for i in range(0, rows):
	for j in range(0, cols):
		if matrix[i][j] == 'f':
			if (i < rows - 1 and i >= 1) and (j < cols - 1 and j >= 1):
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i - 1][j - 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i - 1][j + 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i + 1][j - 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i + 1][j + 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == 0 and j == 0:
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i + 1][j + 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == 0 and j == cols - 1:
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i + 1][j - 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == rows - 1 and j == 0:
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i - 1][j + 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == rows - 1 and j == cols - 1:
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i - 1][j - 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == 0 and (j >= 1 and j < cols - 1):
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i + 1][j - 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i + 1][j + 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif (i >= 1 and i < rows - 1) and j == 0:
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i - 1][j + 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i + 1][j + 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif i == rows - 1 and (j >= 1 and j < cols - 1):
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i - 1][j - 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j + 1])
				lstBuffer.append(matrix[i - 1][j + 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
			elif (i >= 1 and i < rows - 1) and j == cols - 1:
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i + 1][j - 1])
				lstBuffer.append(matrix[i + 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
				lstBuffer = []
				lstBuffer.append(matrix[i][j - 1])
				lstBuffer.append(matrix[i - 1][j - 1])
				lstBuffer.append(matrix[i - 1][j])
				x = sorted(lstBuffer)
				if x[0] == 'a' and x[1] == 'c' and (x[2] == 'e'):
					counter += 1
print(counter)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, m) = LI()
	aa = [S() for _ in range(n)]
	r = 0
	f = set([c for c in 'face'])
	for i in range(n - 1):
		for j in range(m - 1):
			s = set()
			for ii in range(i, i + 2):
				for jj in range(j, j + 2):
					s.add(aa[ii][jj])
			if s == f:
				r += 1
	return r
print(main())


from functools import reduce
M = {'f': 2, 'a': 4, 'c': 8, 'e': 16}
(n, m) = map(int, input().split())
A = []
for i in range(n):
	A.append(input())
cont = 0
B = [[0 for _ in range(m)] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if A[i][j] in M.keys():
			B[i][j] = M[A[i][j]]
for i in range(n - 1):
	for j in range(m - 1):
		cont += 30 == reduce(lambda x, y: x + y, B[i][j:j + 2] + B[i + 1][j:j + 2])
print(cont)


(n, m) = map(int, input().split())
a = []
c = ['f', 'a', 'c', 'e']
c.sort()
for i in range(n):
	a.append(list(input()))
count = 0
for i in range(n - 1):
	for j in range(m - 1):
		b = []
		b.append(a[i][j])
		b.append(a[i][j + 1])
		b.append(a[i + 1][j])
		b.append(a[i + 1][j + 1])
		b.sort()
		if b == c:
			count += 1
print(count)


def test(f, a, c, e):
	face = [f, a, c, e]
	if 'f' in face and 'a' in face and ('c' in face) and ('e' in face):
		return 1
	return 0
import time
(n, m) = (int(i) for i in input().split())
fmap = []
for i in range(n):
	fmap.append(input())
start = time.time()
acc = 0
for i in range(n):
	for j in range(m):
		if fmap[i][j] == 'f':
			if i < n - 1 and j < m - 1:
				acc += test(fmap[i][j], fmap[i][j + 1], fmap[i + 1][j], fmap[i + 1][j + 1])
			if i < n - 1 and j > 0:
				acc += test(fmap[i][j], fmap[i][j - 1], fmap[i + 1][j], fmap[i + 1][j - 1])
			if i > 0 and j < m - 1:
				acc += test(fmap[i][j], fmap[i][j + 1], fmap[i - 1][j], fmap[i - 1][j + 1])
			if i > 0 and j > 0:
				acc += test(fmap[i][j], fmap[i][j - 1], fmap[i - 1][j], fmap[i - 1][j - 1])
print(acc)
finish = time.time()


ans = 0
(n, m) = [int(i) for i in input().split()]
li = [input() for _ in range(n)]
face = set('face')
for i in range(n - 1):
	for j in range(m - 1):
		if set(li[i][j] + li[i + 1][j] + li[i][j + 1] + li[i + 1][j + 1]) == face:
			ans += 1
print(ans)


__author__ = 'taras-sereda'
(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
mat = [input() for i in range(n)]
chars = ['f', 'a', 'c', 'e']
amount = 0
for i in range(n):
	for j in range(m):
		if mat[i][j] in chars:
			f = mat[i][j]
			kand = []
			kand.append(f)
			if mat[min(i + 1, n - 1)][j] in chars and mat[min(i + 1, n - 1)][j] not in kand:
				kand.append(mat[i + 1][j])
				if mat[i][min(j + 1, m - 1)] in chars and mat[i][min(j + 1, m - 1)] not in kand:
					kand.append(mat[i][j + 1])
					if mat[min(i + 1, n - 1)][min(j + 1, m - 1)] in chars and mat[min(i + 1, n - 1)][min(j + 1, m - 1)] not in kand:
						kand.append(mat[i + 1][j + 1])
						if set(kand) == set(chars):
							amount += 1
print(amount)


__author__ = 'Rafael Capucho <rafael.capucho@gmail.com>'

def do_combination(mylist):
	result = []
	for i in range(len(mylist) - 1):
		result.append([mylist[i], mylist[i + 1]])
	return result

def do_group(myinput, size, step=1):
	index = 0
	while index < len(myinput) - 1:
		yield myinput[index:index + size]
		index += step

def do(combinations):
	count = 0
	for elem in combinations:
		group1 = list(do_group(elem[0], 2))
		group2 = list(do_group(elem[1], 2))
		letters = set()
		for i in range(len(group1)):
			letters.add(group1[i][0])
			letters.add(group1[i][1])
			letters.add(group2[i][0])
			letters.add(group2[i][1])
			if {'e', 'f', 'c', 'a'} == letters:
				count += 1
			letters = set()
	return count
the_input = []
(height, _) = map(int, input().split())
for i in range(height):
	the_input.append(input())
print(do(do_combination(the_input)))


import sys
Input = lambda : map(int, input().split())
res = 0
(n, m) = Input()
Pic = list()
for i in range(n):
	Pic.append(input())
Face = 'acef'
for i in range(n):
	for j in range(m):
		if Pic[i][j] in Face:
			try:
				if ''.join(sorted(Pic[i][j] + Pic[i][j + 1] + Pic[i + 1][j] + Pic[i + 1][j + 1])) == Face:
					res += 1
			except:
				pass
print(res)


(n, m) = map(int, input().split(' '))
l = []
res = 0
face = ['f', 'a', 'c', 'e']
face.sort()
for i in range(n):
	col = list(input())
	l.append(col)
for i in range(n - 1):
	for j in range(m - 1):
		temp = []
		if l[i][j] in face:
			temp.append(l[i][j])
			temp.append(l[i + 1][j])
			temp.append(l[i][j + 1])
			temp.append(l[i + 1][j + 1])
		temp.sort()
		if face == temp:
			res += 1
print(res)


(n, m) = map(int, input().split())
img = []
for i in range(n):
	img.append(list(input()))
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		t = sorted([img[i][j], img[i + 1][j], img[i][j + 1], img[i + 1][j + 1]])
		if 'acef' == ''.join(t):
			ans += 1
print(ans)


l1 = [int(x) for x in input().split()]
rows = l1[0]
columns = l1[1]
l2 = []
for x in range(rows):
	l2.append(list(input()))
i = 0
ans = 0
while i < rows - 1:
	j = 0
	while j < columns - 1:
		targ = l2[i][j] + l2[i][j + 1] + l2[i + 1][j] + l2[i + 1][j + 1]
		if 'f' in targ and 'a' in targ and ('c' in targ) and ('e' in targ):
			ans += 1
		j += 1
	i += 1
print(ans)


(n, m) = map(int, input().split())
counter = 0
img = [input() for _ in range(n)]
if n > 1 and m > 1:
	for y in range(n - 1):
		for x in range(m - 1):
			f = set(img[y][x:x + 2] + img[y + 1][x:x + 2])
			if f == set('face'):
				counter += 1
print(counter)


thepair = input().split()
n = int(thepair[0])
m = int(thepair[1])
if n == 1 or m == 1:
	print(0)
else:
	answer = 0
	a = [[0 for i in range(m)] for j in range(n)]
	for r in range(n):
		a[r] = input()
	for r in range(0, n - 1):
		for c in range(0, m - 1):
			s = []
			s.append(a[r][c])
			s.append(a[r + 1][c])
			s.append(a[r][c + 1])
			s.append(a[r + 1][c + 1])
			s = sorted(s)
			if s[0] == 'a' and s[1] == 'c' and (s[2] == 'e') and (s[3] == 'f'):
				answer = answer + 1
	print(answer)


(n, m) = map(int, input().split())
x = []
for i in range(n):
	x.append(input())
c = 0
for i in range(n - 1):
	for j in range(m - 1):
		k = [x[i][j], x[i + 1][j], x[i][j + 1], x[i + 1][j + 1]]
		if ''.join(sorted(k)) == 'acef':
			c += 1
print(c)


(n, m) = list(map(int, input().split()))
grid = [list(input()) for i in range(n)]
cnt = 0
for r in range(n - 1):
	for c in range(m - 1):
		face = ['f', 'a', 'c', 'e']
		if grid[r][c] in face:
			face.remove(grid[r][c])
			if grid[r + 1][c] in face:
				face.remove(grid[r + 1][c])
				if grid[r][c + 1] in face:
					face.remove(grid[r][c + 1])
					if grid[r + 1][c + 1] in face:
						face.remove(grid[r + 1][c + 1])
						cnt += 1
print(cnt)


__author__ = 'Данила'
(n, m) = map(int, input().split())
mat = [['' for i in range(m)] for j in range(n)]
for i in range(n):
	s = input().rstrip()
	for j in range(len(s)):
		mat[i][j] = s[j]
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		mn = set()
		mn.add(mat[i][j])
		mn.add(mat[i + 1][j])
		mn.add(mat[i][j + 1])
		mn.add(mat[i + 1][j + 1])
		if 'f' in mn and 'a' in mn and ('c' in mn) and ('e' in mn):
			cnt += 1
print(cnt)


(n, m) = [int(i) for i in input().split()]
image = [input() for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if len(set([image[i][j], image[i][j + 1], image[i + 1][j], image[i + 1][j + 1]]) & set(['f', 'a', 'c', 'e'])) == 4:
			ans += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
a = []
for i in range(n):
	a.append(input())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		v = [a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1]]
		v.sort()
		if v == ['a', 'c', 'e', 'f']:
			ans = ans + 1
print(ans)


(n, m) = map(int, input().split())
(a, counter) = ([input() for i in range(n)], 0)
for (i, j) in zip(a, a[1:]):
	for k in zip(i, i[1:], j, j[1:]):
		if sorted(k) == [*'acef']:
			counter += 1
print(counter)


(R, C) = map(int, input().split())
AN = 0
M = []
for r in range(R):
	M += [list(input())]
for r in range(R - 1):
	for c in range(C - 1):
		S = set()
		S.add(M[r][c])
		S.add(M[r + 1][c])
		S.add(M[r][c + 1])
		S.add(M[r + 1][c + 1])
		if S == {'f', 'a', 'c', 'e'}:
			AN += 1
print(AN)


def main():
	read = lambda : tuple(map(int, input().split()))
	(h, w) = read()
	m = [input() for i in range(h)]

	def isFace(x, y):
		d = [m[y][x], m[y][x + 1], m[y + 1][x], m[y + 1][x + 1]]
		for c in 'face':
			if not c in d:
				return False
		return True
	k = 0
	for y in range(h - 1):
		for x in range(w - 1):
			if isFace(x, y):
				k += 1
	print(k)
main()


(m, n) = map(int, input().split(' '))
pic = []
count = 0
if m < 2 or n < 2:
	print(0)
	exit()
for i in range(m):
	pic.append(input())
for i in range(m - 1):
	for j in range(n - 1):
		s = pic[i][j:j + 2] + pic[i + 1][j:j + 2]
		if 'f' in s and 'a' in s and ('c' in s) and ('e' in s):
			count += 1
print(count)


(h, w) = map(int, input().split())
ans = 0
image = [input() for _ in range(h)]
face = set('face')
for j in range(h - 1):
	for i in range(w - 1):
		if image[j][i] in face:
			s = {image[j + dj][i + di] for dj in (0, 1) for di in (0, 1)}
			if s == face:
				ans += 1
print(ans)


def face(_list: [[str]], _row: int, _col: int) -> bool:
	s = ['f', 'a', 'c', 'e']
	try:
		s.remove(_list[_row][_col])
		s.remove(_list[_row][_col + 1])
		s.remove(_list[_row + 1][_col])
		s.remove(_list[_row + 1][_col + 1])
	except:
		pass
	if s == []:
		return True
	else:
		return False
(row, col) = map(int, input().split())
rec_table = []
for i in range(row):
	rec_table.append(list(input()))
ans = 0
for i in range(row - 1):
	for j in range(col - 1):
		if face(rec_table, i, j):
			ans += 1
print(ans)


inp = list(map(int, input().split()))
im = []
for j in range(inp[0]):
	im.append(list(input()))
c = 0
i = 0
while i < inp[0] - 1:
	j = 0
	while j < inp[1] - 1:
		s = []
		s.append(im[i][j])
		s.append(im[i + 1][j])
		s.append(im[i + 1][j + 1])
		s.append(im[i][j + 1])
		s.sort()
		if s == sorted(['f', 'a', 'c', 'e']):
			c += 1
		j += 1
	i += 1
print(c)


(n, m) = [int(x) for x in input().split()]
data = []
for i in range(n):
	tmp = input()
	data.append(tmp)
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		tmp = list(sorted([data[i][j], data[i][j + 1], data[i + 1][j], data[i + 1][j + 1]]))
		if tmp == ['a', 'c', 'e', 'f']:
			cnt += 1
print(cnt)


(n, m) = str(input()).split()
n = int(n)
m = int(m)
face = list()
for i in range(n):
	face.append(list(str(input())))
c = 0
for i in range(n - 1):
	for j in range(m - 1):
		line = str()
		line += face[i][j]
		line += face[i][j + 1]
		line += face[i + 1][j]
		line += face[i + 1][j + 1]
		if 'f' in line and 'a' in line and ('c' in line) and ('e' in line):
			c += 1
print(c)


def main():
	[n_rows, n_cols] = [int(_) for _ in input().split()]
	rows = [input() for _ in range(n_rows)]
	face_count = 0
	for i in range(n_rows - 1):
		for j in range(n_cols - 1):
			chars = [rows[i][j], rows[i][j + 1], rows[i + 1][j], rows[i + 1][j + 1]]
			chars.sort()
			if ''.join(chars) == 'acef':
				face_count += 1
	print(face_count)
main()


(n, m) = map(int, input().split())
image = list()
for i in range(n):
	image.append(list(input()))
t = {'f', 'a', 'c', 'e'}
c = 0
for i in range(n):
	for j in range(m):
		if image[i][j] in t:
			if i + 1 < n and image[i + 1][j] in t:
				if j + 1 < m and image[i][j + 1] in t:
					if image[i + 1][j + 1] in t:
						se = set()
						se.add(image[i][j])
						se.add(image[i + 1][j])
						se.add(image[i][j + 1])
						se.add(image[i + 1][j + 1])
						if len(se) == 4:
							c += 1
print(c)


(a, b) = map(int, input().split())
if a == 1 or b == 1:
	print(0)
else:
	c = []
	d = 0
	for i in range(a):
		c += [input()]
	for i in range(a - 1):
		for j in range(b - 1):
			if set([c[i][j], c[i + 1][j], c[i][j + 1], c[i + 1][j + 1]]) == set('face'):
				d += 1
	print(d)


(n, m) = map(int, input().split())
a = []
b = []
ex = ['a', 'c', 'e', 'f']
ans = 0
for i in range(n):
	a.append(input())
for i in range(n - 1):
	for j in range(m - 1):
		b.append(a[i][j])
		b.append(a[i][j + 1])
		b.append(a[i + 1][j])
		b.append(a[i + 1][j + 1])
		b.sort()
		if b == ex:
			ans += 1
		b.clear()
print(ans)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(m - 1):
		s = a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1]
		cnt += 'f' in s and 'a' in s and ('c' in s) and ('e' in s)
print(cnt)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def safe(x, y, n, m):
	return 0 <= x < n and 0 <= y < m

def solve(case):
	(n, m) = sep()
	grid = []
	for i in range(n):
		temp = list(inp())
		grid.append(temp)
	ans = 0
	for i in range(n):
		for j in range(m):
			if safe(i + 1, j, n, m) and safe(i, j + 1, n, m):
				temp = []
				for ii in range(i, i + 2):
					for jj in range(j, j + 2):
						temp.append(grid[ii][jj])
				chck = 'face'
				f = True
				for ii in range(4):
					if chck[ii] not in temp:
						f = False
				if f:
					ans += 1
	print(ans)
testcase(1)


a = []
b = []
n = 0
m = 0

def Init():
	global a, b, n, m
	size = [int(x) for x in input().split(' ')]
	n = size[0]
	m = size[1]
	for i in range(n):
		x = []
		y = input()
		for char in y:
			if char == 'f':
				x.append(1)
			elif char == 'a':
				x.append(5)
			elif char == 'c':
				x.append(21)
			elif char == 'e':
				x.append(85)
			else:
				x.append(0)
		a.append(x)

def Calcu(x, y):
	s = a[x][y] + a[x][y + 1] + a[x + 1][y] + a[x + 1][y + 1]
	if s == 112:
		return True
	else:
		return False

def getResuilt():
	global a, b, n, m
	res = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if Calcu(i, j):
				res += 1
	print(res)
Init()
getResuilt()


(n, m) = map(int, input().split())
picture = []
for i in range(n):
	picture.append([letter for letter in input()])

def check_face(letter, coordinate, matrix):
	needed = ['f', 'a', 'c', 'e']
	needed.pop(needed.index(letter))
	for i in range(coordinate[0], coordinate[0] + 2):
		for j in range(coordinate[1], coordinate[1] + 2):
			if i == coordinate[0] and j == coordinate[1]:
				continue
			if matrix[i][j] in needed:
				needed.pop(needed.index(matrix[i][j]))
			else:
				return False
	if needed == []:
		return True
	else:
		return False
face_count = 0
for i in range(n - 1):
	for j in range(m - 1):
		cursor = picture[i][j]
		if cursor == 'f' or cursor == 'a' or cursor == 'c' or (cursor == 'e'):
			is_face = check_face(cursor, [i, j], picture)
			if is_face:
				face_count += 1
print(face_count)


(n, m) = map(int, input().strip().split())
s = []
for i in range(n):
	In = input()
	tmp = []
	for c in In:
		tmp.append(c)
	s.append(tmp)
ans = 0
tot = 0
dict = {}
for i in range(n - 1):
	for j in range(m - 1):
		tot = tot + 1
		dict[s[i][j]] = tot
		dict[s[i + 1][j]] = tot
		dict[s[i][j + 1]] = tot
		dict[s[i + 1][j + 1]] = tot
		if dict.get('f', -1) != tot or dict.get('a', -1) != tot or dict.get('c', -1) != tot or (dict.get('e', -1) != tot):
			continue
		ans = ans + 1
print(ans)


(a, b) = map(int, input().split())
arr = ['x' * (b + 2)]
r = lambda : list(map(int, input().split()))
c = 0
for i in range(a):
	arr.append('x' + input() + 'x')
arr.append('x' * (b + 2))
valid = list('acef')
for i in range(1, a + 1):
	for j in range(1, b + 1):
		ff = arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1]
		if sorted(list(ff)) == valid:
			c += 1
print(c)


x = list(map(int, input().split(' ')))
(n, m) = (x[0], x[1])
a = []
for i in range(n):
	a.append(input())

def check(x, y):
	mp = set()
	for i in range(x - 1, x + 1):
		for j in range(y - 1, y + 1):
			mp.add(a[i][j])
	return 'f' in mp and 'a' in mp and ('c' in mp) and ('e' in mp)
k = 0
for i in range(1, n):
	for j in range(1, m):
		if check(i, j):
			k += 1
print(k)


(n, m) = map(int, input().split())
(s, count, a) = ('', 0, 'face')
(p1, p2, p3, p4) = (0, 1, m, m + 1)
for _ in range(n):
	s += input()
if n < 2 or m < 2:
	print(count)
else:
	while 1:
		x = ''
		x += s[p1] + s[p2] + s[p3] + s[p4]
		if sorted(x) == sorted(a):
			count += 1
		if p4 == n * m - 1:
			break
		if p2 % m == m - 1:
			p1 += 2
			p2 += 2
			p3 += 2
			p4 += 2
		else:
			p1 += 1
			p2 += 1
			p3 += 1
			p4 += 1
	print(count)


(n, m) = map(int, input().split())
if n == 1 or m == 1:
	print(0)
else:
	r = 0
	grid = []
	for _ in range(n):
		curr_line = list(input())
		grid.append(curr_line)
	for i in range(n - 1):
		for j in range(m - 1):
			curr_square = set()
			curr_square.add(grid[i][j])
			curr_square.add(grid[i][j + 1])
			curr_square.add(grid[i + 1][j])
			curr_square.add(grid[i + 1][j + 1])
			if curr_square == set(['f', 'a', 'c', 'e']):
				r += 1
	print(r)


(n, m) = map(int, input().split())
g = [input() for i in range(n)]

def solve(sub):
	chars = ''
	for x in sub:
		for y in x:
			chars += y
	return sorted(chars) == sorted('face')
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if solve([[g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]]]):
			ans += 1
print(ans)


def face_detection():
	size = list(map(int, input().split()))
	if size[0] == 1:
		return 0
	maze = []
	dic = {'f': 1, 'a': 2, 'c': 3, 'e': 4}
	for i in range(size[0]):
		maze.append(input())
	output = 0
	for i in range(1, len(maze)):
		for j in range(1, len(maze[i])):
			if maze[i][j] in dic:
				alt_dic = dic.copy()
				alt_dic.pop(maze[i][j])
				if maze[i - 1][j - 1] in alt_dic:
					alt_dic.pop(maze[i - 1][j - 1])
					if maze[i - 1][j] in alt_dic:
						alt_dic.pop(maze[i - 1][j])
						if maze[i][j - 1] in alt_dic:
							output += 1
	return output
A = face_detection()
print(A)


firstLine = [int(n) for n in input().split()]
matrix = []
for i in range(0, firstLine[0]):
	matrix.append(str(input()))
total = 0
for i in range(0, len(matrix) - 1):
	for j in range(0, len(matrix[0]) - 1):
		temp = ''
		temp += matrix[i][j]
		temp += matrix[i][j + 1]
		temp += matrix[i + 1][j]
		temp += matrix[i + 1][j + 1]
		if 'f' in temp and 'a' in temp and ('c' in temp) and ('e' in temp):
			total += 1
print(total)


import math
import sys
from decimal import Decimal
inp = list(map(int, input().split()))
n = inp[0]
m = inp[1]
c = []
for i in range(0, n):
	s = input()
	c.append([])
	for j in range(0, m):
		c[i].append(s[j])
ans = 0
for i in range(0, n - 1):
	for j in range(0, m - 1):
		t = c[i][j] + c[i + 1][j] + c[i + 1][j + 1] + c[i][j + 1]
		if 'a' in t and 'f' in t and ('c' in t) and ('e' in t):
			ans += 1
print(ans)


(n, m) = map(int, input().split(' '))
a = [input() for x in range(n)]
print(sum((sorted(a[x][y:y + 2] + a[x + 1][y:y + 2]) == sorted('face') for x in range(n - 1) for y in range(m - 1))))


(n, m) = map(int, input().split())
answer = 0
face_detector = [input() for i in range(n)]
for i in range(n):
	for j in range(m):
		if face_detector[i][j] == 'f':
			if i > 0:
				if j > 0:
					if face_detector[i - 1][j] == 'a':
						if face_detector[i - 1][j - 1] == 'c':
							if face_detector[i][j - 1] == 'e':
								answer += 1
						elif face_detector[i - 1][j - 1] == 'e':
							if face_detector[i][j - 1] == 'c':
								answer += 1
					elif face_detector[i - 1][j] == 'c':
						if face_detector[i - 1][j - 1] == 'a':
							if face_detector[i][j - 1] == 'e':
								answer += 1
						elif face_detector[i - 1][j - 1] == 'e':
							if face_detector[i][j - 1] == 'a':
								answer += 1
					elif face_detector[i - 1][j] == 'e':
						if face_detector[i - 1][j - 1] == 'c':
							if face_detector[i][j - 1] == 'a':
								answer += 1
						elif face_detector[i - 1][j - 1] == 'a':
							if face_detector[i][j - 1] == 'c':
								answer += 1
				if j < m - 1:
					if face_detector[i - 1][j] == 'a':
						if face_detector[i - 1][j + 1] == 'c':
							if face_detector[i][j + 1] == 'e':
								answer += 1
						elif face_detector[i - 1][j + 1] == 'e':
							if face_detector[i][j + 1] == 'c':
								answer += 1
					elif face_detector[i - 1][j] == 'c':
						if face_detector[i - 1][j + 1] == 'a':
							if face_detector[i][j + 1] == 'e':
								answer += 1
						elif face_detector[i - 1][j + 1] == 'e':
							if face_detector[i][j + 1] == 'a':
								answer += 1
					elif face_detector[i - 1][j] == 'e':
						if face_detector[i - 1][j + 1] == 'c':
							if face_detector[i][j + 1] == 'a':
								answer += 1
						elif face_detector[i - 1][j + 1] == 'a':
							if face_detector[i][j + 1] == 'c':
								answer += 1
			if i < n - 1:
				if j > 0:
					if face_detector[i + 1][j] == 'a':
						if face_detector[i + 1][j - 1] == 'c':
							if face_detector[i][j - 1] == 'e':
								answer += 1
						elif face_detector[i + 1][j - 1] == 'e':
							if face_detector[i][j - 1] == 'c':
								answer += 1
					elif face_detector[i + 1][j] == 'c':
						if face_detector[i + 1][j - 1] == 'a':
							if face_detector[i][j - 1] == 'e':
								answer += 1
						elif face_detector[i + 1][j - 1] == 'e':
							if face_detector[i][j - 1] == 'a':
								answer += 1
					elif face_detector[i + 1][j] == 'e':
						if face_detector[i + 1][j - 1] == 'c':
							if face_detector[i][j - 1] == 'a':
								answer += 1
						elif face_detector[i + 1][j - 1] == 'a':
							if face_detector[i][j - 1] == 'c':
								answer += 1
				if j < m - 1:
					if face_detector[i + 1][j] == 'a':
						if face_detector[i + 1][j + 1] == 'c':
							if face_detector[i][j + 1] == 'e':
								answer += 1
						elif face_detector[i + 1][j + 1] == 'e':
							if face_detector[i][j + 1] == 'c':
								answer += 1
					elif face_detector[i + 1][j] == 'c':
						if face_detector[i + 1][j + 1] == 'a':
							if face_detector[i][j + 1] == 'e':
								answer += 1
						elif face_detector[i + 1][j + 1] == 'e':
							if face_detector[i][j + 1] == 'a':
								answer += 1
					elif face_detector[i + 1][j] == 'e':
						if face_detector[i + 1][j + 1] == 'c':
							if face_detector[i][j + 1] == 'a':
								answer += 1
						elif face_detector[i + 1][j + 1] == 'a':
							if face_detector[i][j + 1] == 'c':
								answer += 1
print(answer)


(n, m) = map(int, input().split())
a = []
k = 0
for i in range(n):
	a.append(input())
for x in range(n - 1):
	for y in range(m - 1):
		s = a[x][y:y + 2] + a[x + 1][y:y + 2]
		if ('f' in s) & ('a' in s) & ('c' in s) & ('e' in s):
			k += 1
print(k)


string = input()
numbers = string.split()
a = int(numbers[0])
b = int(numbers[1])
rows = []
for x in range(a):
	row = input()
	rows.append(row)
faces = 0
for x in range(a - 1):
	for y in range(b - 1):
		p = rows[x]
		q = rows[x + 1]
		face = ['f', 'a', 'c', 'e']
		square = [p[y], p[y + 1], q[y], q[y + 1]]
		condition = True
		for z in face:
			if not z in square:
				condition = False
		if condition:
			faces += 1
print(faces)


(n, m) = (int(x) for x in input().split())
a = []
for i in range(n):
	a.append(input().strip())
ans = 0
for i in range(n - 1):
	for j in range(m - 1):
		if sorted([a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]]) == sorted(['f', 'a', 'c', 'e']):
			ans += 1
print(ans)


(h, w) = [int(x) for x in input().split(' ')]
b = []
faces = 0
for i in range(h):
	b += [input()]
for i in range(h - 1):
	for j in range(w - 1):
		if ''.join(sorted(b[i][j:j + 2] + b[i + 1][j:j + 2])) == 'acef':
			faces += 1
print(faces)