n = int(input()) g = [input() for _ in range(n)] ans = 0 for i in range(n): if g[i].count("A") == n - 1 and "B" not in g[i]: ans += 1 for j in range(n): t = [] for i in range(n): t.append(g[i][j]) if t.count("A") == n - 1 and "B" not in t: ans += 1 t = [] for i in range(n): t.append(g[i][i]) if t.count("A") == n - 1 and "B" not in t: ans += 1 t = [] for i in range(n): t.append(g[i][n - i - 1]) if t.count("A") == n - 1 and "B" not in t: ans += 1 print(ans)