def decode(ch): if ch == "A": return 1 if ch == "B": return 2 return 0 def transpose(A): H, W = len(A), len(A[0]) return [[A[i][j] for i in range(H)] for j in range(W)] DIR4 = [(1, 0), (0, 1), (-1, 0), (0, -1)] DIR8 = DIR4 + [(1, 1), (1, -1), (-1, -1), (-1, 1)] N = int(input()) S = [[decode(ch) for ch in input()] for i in range(N)] from collections import Counter def is_good(C): return C[1] == N-1 and C[2] == 0 def check_rows(A): H, W = len(A), len(A[0]) res = 0 for i in range(H): row = A[i] C = Counter(row) res += is_good(C) return res a1 = check_rows(S) a2 = check_rows(transpose(S)) ans = a1+a2 d1 = Counter([S[i][i] for i in range(N)]) d2 = Counter([S[i][N-1-i] for i in range(N)]) ans += is_good(d1) + is_good(d2) print(ans)