program find_symmetries
  implicit none
  integer :: n, s(600,300), m, a, i, j
  character(300) :: t
  logical :: ng
  s = 0
  read(*,*) n
  do i = 1, n
    read(*,*) t
    t = trim(adjustl(t))
    do j = 1, n
      s(i,j) = ichar(t(j:j))-97
    end do
    s(i+n,1:n) = s(i,1:n)
  end do
  m = 0
  do a = 0, n-1
    ng = .false.
    do i = 1, n
      do j = 1, n
        if (s(i+a,j).ne.s(j+a,i)) then
          ng = .true.
          exit
        end if
      end do
      if (ng) exit
    end do
    if (.not.ng) m = m + 1
  end do
  write(*,'(i0)') n*m
  stop
end program find_symmetries