module HowManyTimesReached def solve(n, ss) [(0 ... n).reduce(0){|c, i| c + yoko(n, ss, i)}, (0 ... n).reduce(0){|c, i| c + tate(n, ss, i)}, naname(n, ss)].sum end def yoko(n, ss, i) x = (0 ... n).map{|j| ss[i][j]} if x.count('A') == n - 1 && x.count('.') == 1 1 else 0 end end def tate(n, ss, i) x = (0 ... n).map{|j| ss[j][i]} if x.count('A') == n - 1 && x.count('.') == 1 1 else 0 end end def naname(n, ss) ret = 0 x = (0 ... n).map{|i| ss[i][i]} if x.count('A') == n - 1 && x.count('.') == 1 ret += 1 end x = (0 ... n).map{|i| ss[i][n - 1 - i]} if x.count('A') == n - 1 && x.count('.') == 1 ret += 1 end ret end module_function :solve, :yoko, :tate, :naname end n = gets.chomp.to_i ss = n.times.map{ gets.chomp } puts HowManyTimesReached.solve(n, ss)