input: from typing import List
  
  def number_of_right_triangles(grid: List[List[int]]) -> int:
      """
      You are given a 2D boolean matrix grid.
  
      Return an integer that is the number of right triangles that can be made with the 3 elements of grid such that all of them have a value of 1.
  
      Note:
  
      A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements do not have to be next to each other.
  
      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 <= grid.length <= 1000
      1 <= grid[i].length <= 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:
                  for k in range(rows):
                      if k != i and grid[k][j] == 1:
                          for l in range(cols):
                              if l != j and grid[i][l] == 1:
                                  if grid[k][l] == 1:
                                      count += 1
      
      return count // 2
  