program random_tournament
  implicit none
  integer :: n, a(2000,2000) = 0, i, j, k, d, ans = 0
  logical :: dpl(2000,2000) = .false., dpr(2000,2000) = .false.
  character(2000) :: s
  read(*,*) n
  do i = 2, n
    read(*,*) s
    do j = 1, i-1
      a(i,j) = ichar(s(j:j))-48
      a(j,i) = 1-a(i,j)
    end do
  end do
  do i = 1, n
    dpl(i,i) = .true.
    dpr(i,i) = .true.
  end do
  do d = 1, n-1
    do i = 1, n-d
      j = i+d
      do k = i, j
        if (k /= i) dpl(i,j) = dpl(i,j) .or. (a(i,k) == 1 .and. dpl(k,j) .and. dpr(k,i+1))
        if (k /= j) dpr(j,i) = dpr(j,i) .or. (a(k,j) == 0 .and. dpl(k,j-1) .and. dpr(k,i))
      end do
    end do
  end do
  do i = 1, n
    if (dpl(i,n) .and. dpr(i,1)) ans = ans+1
  end do
  write(*,'(i0)') ans
end program random_tournament