input: from typing import List
  
  def count_right_triangles(grid: List[List[int]]) -> int:
      """
      Given a 2D boolean matrix grid.
  
      Return the total number of right triangles that can be formed using 3 elements of the grid, ensuring all these elements have a value of 1.
  
      Note:
  
      A set of 3 elements constitutes a right triangle if one element is aligned horizontally with another and vertically with the third. The elements do not need to be adjacent.
  
      Examples:
      >>> grid = [[0, 1, 0], [0, 1, 1], [0, 1, 0]]
      2
      >>> grid = [[1, 0, 0, 0], [0, 1, 0, 1], [1, 0, 0, 0]]
      0
      >>> grid = [[1, 0, 1], [1, 0, 0], [1, 0, 0]]
      2
  
      Constraints:
      1 <= len(grid) <= 1000
      1 <= len(grid[0]) <= 1000
      0 <= grid[i][j] <= 1
      """
output:     
      count = 0
      rows = len(grid)
      cols = len(grid[0])
  
      for i in range(rows):
          for j in range(cols):
              if grid[i][j] == 1:
                  row_count = sum(grid[i])
                  col_count = sum(grid[k][j] for k in range(rows))
                  
                  count += (row_count - 1) * (col_count - 1)
  
      return count
  