#P3166. Counting Triangles on a Grid

    ID: 16423 Type: Default 1000ms 256MiB

Counting Triangles on a Grid

Counting Triangles on a Grid

Given an \(N \times M\) grid, count the number of triangles that can be formed using grid points as vertices. The three points of a valid triangle must not be collinear.

inputFormat

The input consists of two space-separated integers: \(N\) and \(M\) (where \(1 \leq N, M \leq 50\)), representing the number of rows and columns of the grid respectively.

outputFormat

Output a single integer representing the number of triangles that can be formed by choosing three grid points that are not collinear.

sample

2 2
4