program find_symmetries
  implicit none
  integer :: n, s(600,600), m, a, b, 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:2*n) = s(i,1:n)
    s(i+n,1:2*n) = s(i,1:2*n)
  end do
  m = 0
  do a = 0, n-1
    do b = 0, n-1
      ng = .false.
      do i = 1, n
        do j = 1, n
          if (s(i+a,j+b).ne.s(j+a,i+b)) then
            ng = .true.
            exit
          end if
        end do
        if (ng) exit
      end do
      if (.not.ng) m = m + 1
    end do
  end do
  write(*,'(i0)') m
  stop
end program find_symmetries