input: from typing import List
  
  def count_right_triangles(matrix: List[List[int]]) -> int:
      """
      You have a 2D boolean array matrix.
  
      The function returns how many right triangles can be formed with three elements in the matrix, where each element equals 1.
  
      Note:
  
      A set of 3 elements constitutes a right triangle if one element shares its row with another and its column with the third. The elements don't need to be adjacent.
  
      Examples:
      >>> matrix = [[0,1,0],[0,1,1],[0,1,0]]
      2
      >>> matrix = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]
      0
      >>> matrix = [[1,0,1],[1,0,0],[1,0,0]]
      2
  
      Constraints:
      1 <= matrix.length <= 1000
      1 <= matrix[i].length <= 1000
      0 <= matrix[i][j] <= 1
      """
output:     rows = len(matrix)
      cols = len(matrix[0])
      count = 0
  
      for i in range(rows):
          for j in range(cols):
              if matrix[i][j] == 1:
                  row_count = sum(matrix[i])
                  col_count = sum(matrix[k][j] for k in range(rows))
                  count += (row_count - 1) * (col_count - 1)
  
      return count