n=int(input()) s=[input() for _ in range(n)] ans=0 for i in range(n): cnt=0 for j in range(n): if s[i][j]=='A': cnt+=1 if s[i][j]=='B': cnt-=1 if cnt==n-1: ans+=1 for j in range(n): cnt=0 for i in range(n): if s[i][j]=='A': cnt+=1 if s[i][j]=='B': cnt-=1 if cnt==n-1: ans+=1 cnt=0 for i in range(n): if s[i][i]=='A': cnt+=1 elif s[i][i]=='B': cnt-=1 if cnt==n-1: ans+=1 cnt=0 for i in range(n): if s[-i-1][i]=='A': cnt+=1 elif s[-i-1][i]=='B': cnt-=1 if cnt==n-1: ans+=1 print(ans)