Count Right Triangles in Grid

Given a binary matrix grid, count right triangles whose three vertices are 1 cells and whose two perpendicular legs are horizontal and vertical. For every 1 at (r,c), choose another 1 in its row and another 1 in its column. The two choices form one right triangle with the right angle at (r,c). Return the count modulo 1_000_000_007.

Examples
Input: [1,2,3]
Output: 0
Hints

Count Right Triangles in Grid

Given a binary matrix `grid`, count right triangles whose three vertices are `1` cells and whose two perpendicular legs are horizontal and vertical. For every `1` at `(r,c)`, choose another `1` in its row and another `1` in its column. The two choices form one right triangle with the right angle at `(r,c)`. Return the count modulo `1_000_000_007`.